﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using RTUParameterConfig.Controls;
using RTUParameterConfig.Class;
using DevExpress.XtraEditors;

namespace RTUParameterConfig
{
    public partial class ParameterConfig : UserControl
    {
        /// <summary>
        ///已配置的设备配置信息
        /// </summary>
        public static StructData.RtuConfigInfo rtuConfigInfo;

        /// <summary>
        /// 是否加载数据
        /// </summary>
        public static bool isLoadData = false;

        /// <summary>
        /// 已选设备1集合
        /// </summary>
        public ArrayList listDevice1 = new ArrayList();

        /// <summary>
        /// 已选设备2集合
        /// </summary>
        public ArrayList listDevice2 = new ArrayList();

        /// <summary>
        /// 水温数据来源集合
        /// </summary>
        public ArrayList listWaterTemperature = new ArrayList();

        /// <summary>
        /// 主程序窗体名称(处理调试消息)
        /// </summary>
        public static string mainFormName = string.Empty;

        /// <summary>
        /// 消息ID
        /// </summary>
        public const int debugMsg = 1025;

        /// <summary>
        /// 参数配置数据长度
        /// </summary>
        public static int paraDataLength = 1400;

        public string showPassWord = "1";
        public  int flag = 0;
        public  int flag1 = 0;
        public  int flag2 = 0;

        public ParameterConfig()
        {
            InitializeComponent();
            InitForm();
            rtuConfigInfo = DefaultConfig();
        }

        protected override void CreateHandle()
        {
            if (!IsHandleCreated)
            {
                try
                {
                    base.CreateHandle();
                }
                catch { }
                finally
                {
                    if (!IsHandleCreated)
                    {
                        base.RecreateHandle();
                    }
                }
            }
        }

        public void InitShowControl(int index)
        {
            txtBox1.Enabled = true;
            groupControl7.Visible = true;
            groupControl6.Visible = true;
            groupControl5.Visible = true;
            groupControl7.Enabled = true;
            groupControl6.Enabled = true;
            groupControl5.Enabled = true;
            groupControl1.Location = new Point(613, 277);

            if (index == 0)
            {
                txtBox1.Enabled = false;
                groupControl7.Visible = false;
                groupControl6.Visible = false;
                groupControl5.Visible = false;
                groupControl1.Location = groupControl6.Location;
            }

            if (index == 1)
            {
                txtBox1.Enabled = true;
                groupControl7.Enabled = false;
                groupControl6.Enabled = false;
                groupControl5.Enabled = false;
            }

            //if (index == 2)
            //{
            //    txtBox1.Enabled = true;
            //    groupControl7.Enabled = true;
            //    groupControl6.Enabled = true;
            //    groupControl5.Enabled = true;
            //}
            if (showPassWord == "0")
            {
                txtBox1.Enabled = true;
            }
        }

        public void SetValue(string strMainFormName)
        {
            mainFormName = strMainFormName;
        }

        private void InitForm()
        {
            //基本配置
            cbb1.Properties.Items.AddRange(Common.StationType);
            cbb1.SelectedIndex = 0;
            cbb2.Properties.Items.AddRange(Common.WorkType);
            cbb2.SelectedIndex = 0;
            cbb3.Properties.Items.AddRange(Common.OpenStatus);
            cbb3.SelectedIndex = 0;
            cbb4.Properties.Items.AddRange(Common.OpenStatus);
            cbb4.SelectedIndex = 0;
            cbb7.Properties.Items.AddRange(Common.Function_485_3);
            cbb7.SelectedIndex = 0;
            nud4.Properties.Items.AddRange(Common.TimingReport);
            nud4.SelectedIndex = 0;
            cbb8.Properties.Items.AddRange(Common.OpenStatus);
            cbb8.SelectedIndex = 0;
            nud5.Properties.Items.AddRange(Common.OpenStatus);
            nud5.SelectedIndex = 1;



            cbbNud1.Properties.Items.Add(new ListItem("1", 1));
            cbbNud1.Properties.Items.Add(new ListItem("2", 2));
            cbbNud1.Properties.Items.Add(new ListItem("3", 3));
            cbbNud1.Properties.Items.Add(new ListItem("4", 4));
            cbbNud1.Properties.Items.Add(new ListItem("5", 5));
            cbbNud1.Properties.Items.Add(new ListItem("6", 6));
            cbbNud1.Properties.Items.Add(new ListItem("10", 10));
            cbbNud1.Properties.Items.Add(new ListItem("12", 12));
            cbbNud1.Properties.Items.Add(new ListItem("15", 15));
            cbbNud1.Properties.Items.Add(new ListItem("20", 20));
            cbbNud1.Properties.Items.Add(new ListItem("30", 30));
            cbbNud1.Properties.Items.Add(new ListItem("60", 60));
            cbbNud1.Properties.Items.Add(new ListItem("120", 120));
            cbbNud1.Properties.Items.Add(new ListItem("180", 180));
            cbbNud1.Properties.Items.Add(new ListItem("240", 240));
            cbbNud1.SelectedIndex = 0;

            cbbNud2.Properties.Items.Add(new ListItem("1", 1));
            cbbNud2.Properties.Items.Add(new ListItem("2", 2));
            cbbNud2.Properties.Items.Add(new ListItem("3", 3));
            cbbNud2.Properties.Items.Add(new ListItem("4", 4));
            cbbNud2.Properties.Items.Add(new ListItem("5", 5));
            cbbNud2.Properties.Items.Add(new ListItem("6", 6));
            cbbNud2.Properties.Items.Add(new ListItem("10", 10));
            cbbNud2.Properties.Items.Add(new ListItem("12", 12));
            cbbNud2.Properties.Items.Add(new ListItem("15", 15));
            cbbNud2.Properties.Items.Add(new ListItem("20", 20));
            cbbNud2.Properties.Items.Add(new ListItem("30", 30));
            cbbNud2.Properties.Items.Add(new ListItem("60", 60));
            cbbNud2.SelectedIndex = 0;

            //以太网配置
            groupControl1.Visible = false;
            cbbYt1.Properties.Items.AddRange(Common.OpenStatus);
            cbbYt1.SelectedIndex = 0;
            cbbYt2.Properties.Items.AddRange(Common.OpenStatus);
            cbbYt2.SelectedIndex = 0;
            //中心站配置
            cbb11.Properties.Items.AddRange(Common.TransportProtocol);
            cbb11.SelectedIndex = 0;
            cbb21.Properties.Items.AddRange(Common.TransportProtocol);
            cbb21.SelectedIndex = 0;
            cbb31.Properties.Items.AddRange(Common.TransportProtocol);
            cbb31.SelectedIndex = 0;
            cbb12.Properties.Items.AddRange(Common.ReportProtocol);
            cbb12.SelectedIndex = 0;
            cbb22.Properties.Items.AddRange(Common.ReportProtocol);
            cbb22.SelectedIndex = 0;
            cbb32.Properties.Items.AddRange(Common.ReportProtocol);
            cbb32.SelectedIndex = 0;
            cbb13.Properties.Items.AddRange(Common.HardwareInterface);
            cbb13.SelectedIndex = 0;
            cbb23.Properties.Items.AddRange(Common.HardwareInterface);
            cbb23.SelectedIndex = 0;
            cbb33.Properties.Items.AddRange(Common.HardwareInterface);
            cbb33.SelectedIndex = 0;
            cbb5.Properties.Items.AddRange(Common.OpenStatus);
            cbb5.SelectedIndex = 0;
            cbb6.Properties.Items.AddRange(Common.OpenStatus);
            cbb6.SelectedIndex = 0;

            //4-20mA设置
            c1.Properties.Items.AddRange(Common.OpenStatus);
            c1.SelectedIndex = 0;
            c3.Properties.Items.AddRange(Common.OutType);
            c3.SelectedIndex = 0;
            c11.Properties.Items.AddRange(Common.OutSelect);
            c11.SelectedIndex = 0;
            c21.Properties.Items.AddRange(Common.OutSelect);
            c21.SelectedIndex = 0;
            c31.Properties.Items.AddRange(Common.OutSelect);
            c31.SelectedIndex = 0;
            c41.Properties.Items.AddRange(Common.OutSelect);
            c41.SelectedIndex = 0;
            d1.Properties.Items.AddRange(Common.OpenStatus);
            d1.SelectedIndex = 0;
            d11.Properties.Items.AddRange(Common.InSelect);
            d11.SelectedIndex = 0;
            d21.Properties.Items.AddRange(Common.InSelect);
            d21.SelectedIndex = 0;
        }

        /// <summary>
        /// 绑定水位计算来源1选项
        /// </summary>
        public void BindFlowList1()
        {
            ListItem item = null;
            int intValue1 = cbbDm1.SelectedIndex;
            int intValue = -1;
            if (cbbJs1.SelectedItem != null)
            {
                intValue = (cbbJs1.SelectedItem as ListItem).Value;
            }
            cbbJs1.Properties.Items.Clear();

            if (listDevice1.Contains("0"))
            {
                item = new ListItem("水位计1", 0);
                cbbJs1.Properties.Items.Add(item);
            }

            if ((listDevice1.Contains("0") && listDevice1.Contains("1")) || listDevice1.Contains("01"))
            {
                item = new ListItem("水位计1+流速1", 1);
                cbbJs1.Properties.Items.Add(item);
            }

            if ((listDevice1.Contains("0") && listDevice1.Contains("3")) || (listDevice1.Contains("3") && listDevice1.Contains("01")))
            {
                item = new ListItem("水位计1+闸位计1", 2);
                cbbJs1.Properties.Items.Add(item);
            }

            //if (listDevice2.Contains("0") && listDevice1.Contains("20"))
            //{
            //    item = new ListItem("流量计1+水位计2", 3);
            //    cbbJs1.Properties.Items.Add(item);
            //}
            //else
            //{
            //    if (listDevice1.Contains("20"))
            //    {
            //        item = new ListItem("流量计1(内置水位)", 4);
            //        cbbJs1.Properties.Items.Add(item);
            //    }
            //}

            //if (listDevice1.Contains("24"))
            //{
            //    item = new ListItem("流量计1(内置水位)", 4);
            //    cbbJs1.Properties.Items.Add(item);
            //}

            if (listDevice1.Contains("2"))
            {
                item = new ListItem("流量计1(直接输出)", 3);
                cbbJs1.Properties.Items.Add(item);
            }

            if (listDevice1.Contains("4"))
            {
                item = new ListItem("水位计1+多流速", 4);
                cbbJs1.Properties.Items.Add(item);
            }

            if (cbbJs1.Properties.Items.Count > 0)
            {
                if (intValue != -1)
                {
                    for (int i = 0; i < cbbJs1.Properties.Items.Count; i++)
                    {
                        if (intValue == (cbbJs1.Properties.Items[i] as ListItem).Value)
                        {
                            cbbJs1.SelectedIndex = i;
                            cbbDm1.SelectedIndex = intValue1;
                            return;
                        }
                    }
                }
                cbbJs1.SelectedIndex = 0;
            }
            else
            {
                cbbJs1.SelectedIndex = -1;
                cbbDm1.Properties.Items.Clear();
                cbbDm1.SelectedIndex = -1;
                btnYc1.Visible = false;
                if (cbbJs2.Properties.Items.Count == 0)
                {
                    btnWaterLevelSetting.Visible = false;
                }
            }
        }

        /// <summary>
        /// 绑定水位计算来源2选项
        /// </summary>
        public void BindFlowList2()
        {
            ListItem item = null;
            int intValue1 = cbbDm2.SelectedIndex;
            int intValue = -1;
            if (cbbJs2.SelectedItem != null)
            {
                intValue = (cbbJs2.SelectedItem as ListItem).Value;
            }
            cbbJs2.Properties.Items.Clear();

            if (listDevice2.Contains("0"))
            {
                item = new ListItem("水位计2", 0);
                cbbJs2.Properties.Items.Add(item);
            }

            if ((listDevice2.Contains("0") && listDevice2.Contains("1")) || listDevice2.Contains("01"))
            {
                item = new ListItem("水位计2+流速2", 1);
                cbbJs2.Properties.Items.Add(item);
            }

            if (listDevice2.Contains("0") && listDevice2.Contains("3") || (listDevice2.Contains("3") && listDevice2.Contains("01")))
            {
                item = new ListItem("水位计2+闸位计2", 2);
                cbbJs2.Properties.Items.Add(item);
            }

            //if (listDevice1.Contains("0") && listDevice2.Contains("21"))
            //{
            //    item = new ListItem("流量计2+水位计1", 3);
            //    cbbJs2.Properties.Items.Add(item);
            //}
            //else
            //{
            //    if (listDevice2.Contains("21"))
            //    {
            //        item = new ListItem("流量计2(内置水位)", 4);
            //        cbbJs2.Properties.Items.Add(item);
            //    }
            //}

            //if (listDevice2.Contains("25"))
            //{
            //    item = new ListItem("流量计1(内置水位)", 4);
            //    cbbJs2.Properties.Items.Add(item);
            //}

            if (listDevice2.Contains("2"))
            {
                item = new ListItem("流量计2(直接输出)", 3);
                cbbJs2.Properties.Items.Add(item);
            }

            if (cbbJs2.Properties.Items.Count > 0)
            {
                if (intValue != -1)
                {
                    for (int i = 0; i < cbbJs2.Properties.Items.Count; i++)
                    {
                        if (intValue == (cbbJs2.Properties.Items[i] as ListItem).Value)
                        {
                            cbbJs2.SelectedIndex = i;
                            cbbDm2.SelectedIndex = intValue1;
                            return;
                        }
                    }
                }
                cbbJs2.SelectedIndex = 0;
            }
            else
            {
                cbbJs2.SelectedIndex = -1;
                cbbDm2.Properties.Items.Clear();
                cbbDm2.SelectedIndex = -1;
                btnYc2.Visible = false;
                if (cbbJs1.Properties.Items.Count == 0)
                {
                    btnWaterLevelSetting.Visible = false;
                }
            }
        }

        /// <summary>
        /// 绑定水温数据来源
        /// </summary>
        public void BindWaterTemperature()
        {
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is WaterTemperature)
                {
                    WaterTemperature wl = sp1.Controls[i] as WaterTemperature;
                    wl.BindList(listWaterTemperature);
                    return;
                }
            }
        }

        /// <summary>
        /// 检查雷达流量计是否包含水位和流速
        /// </summary>
        /// <param name="index">设备标识</param>
        /// <param name="deviceNo">流量设备序号</param>
        /// <returns>true,false</returns>
        public bool CheckWaterLevelAndCurrentSpeed(int index, int deviceNo)
        {
            string strMsg = Common.FlowmeterList[deviceNo].ToString() + "已使用{0}，请删除{1}！";
            string strMsg1 = string.Empty;
            string strMsg2 = string.Empty;
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is WaterLevel)
                {
                    WaterLevel wl = (WaterLevel)sp1.Controls[i];
                    if (wl.cbbType.SelectedIndex == index)
                    {
                        strMsg1 = wl.cbbType.EditValue.ToString();
                        strMsg2 = Common.WaterLevelList[wl.DeviceSelectNo].ToString() + wl.cbbType.EditValue.ToString();
                        //Common.ShowErrorMessage(string.Format("{0}已使用{1}，请删除{2}{1}！", Common.FlowmeterList[deviceNo].ToString(), wl.cbbType.EditValue.ToString(), Common.WaterLevelList[wl.DeviceSelectNo].ToString()));
                        continue;
                    }
                }

                if (sp1.Controls[i] is CurrentSpeed)
                {
                    CurrentSpeed cs = sp1.Controls[i] as CurrentSpeed;
                    if (cs.cbbType.SelectedIndex == index)
                    {
                        if (strMsg1 != string.Empty)
                        {
                            strMsg1 = strMsg1 + "、" + cs.cbbType.EditValue.ToString();
                            strMsg2 = strMsg2 + "、" + Common.CurrentSpeedList[cs.DeviceSelectNo].ToString() + cs.cbbType.EditValue.ToString();
                        }
                        else
                        {
                            strMsg1 = cs.cbbType.EditValue.ToString();
                            strMsg2 =  Common.CurrentSpeedList[cs.DeviceSelectNo].ToString() + cs.cbbType.EditValue.ToString();
                        }
                        //Common.ShowErrorMessage(string.Format("{0}已使用{1}，请删除{2}{1}！", Common.FlowmeterList[deviceNo].ToString(), cs.cbbType.EditValue.ToString(), Common.CurrentSpeedList[cs.DeviceSelectNo].ToString()));
                        continue;
                    }
                }
            }

            if (strMsg1 != string.Empty)
            {
                Common.ShowErrorMessage(string.Format(strMsg, strMsg1, strMsg2));
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 检查闸位计是否包含水位
        /// </summary>
        /// <param name="index">设备标识</param>
        /// <returns>true,false</returns>
        public bool CheckWaterLevel(int index)
        {
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is WaterLevel)
                {
                    WaterLevel wl = (WaterLevel)sp1.Controls[i];
                    if (wl.cbbType.SelectedIndex == index)
                    { 
                        return true;
                    }
                }

                if (sp1.Controls[i] is Flowmeters)
                {
                    Flowmeters f = (Flowmeters)sp1.Controls[i];
                    if (f.cbbType.SelectedIndex == index)
                    {
                        if (f.DeviceSelectNo == 0 || f.DeviceSelectNo == 5)
                        {
                            return true;
                        }
                    }
                }

                if (sp1.Controls[i] is Flowmeters1)
                {
                    Flowmeters1 f1 = (Flowmeters1)sp1.Controls[i];
                    if (f1.cbbType.SelectedIndex == index)
                    {
                        return true;
                    }
                }

                if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                {
                    WaterLevelAndCurrentSpeed wc = (WaterLevelAndCurrentSpeed)sp1.Controls[i];
                    if (wc.cbbType.SelectedIndex == index)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public void InitSoilNo()
        {
            int index = 0;
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is Soil)
                {
                    Soil s = (Soil)sp1.Controls[i];
                    s.InitValue(10, index, s.DeviceSelectNo);
                    index++;
                }
            }

        }
        public void InitFlag(int flags)
        {
            if (flag ==2)
            {
                flag2 = 0;
            }else if (flag == 1)
            {
                flag1 = 0;
            }
            else
            {
                flag = 0;
            }
        }
        
        public void InitOsmoticPressureNo()
        {
            int index = 0;
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is OsmoticPressure)
                {
                    OsmoticPressure s = (OsmoticPressure)sp1.Controls[i];
                    s.InitValue(11, index, s.DeviceSelectNo);
                    index++;
                }
            }
        }

        /// <summary>
        /// 添加设备判断
        /// </summary>
        /// <param name="intType">设备类型</param>
        /// <param name="intCount">个数</param>
        /// <param name="index">第几个</param>
        /// <returns>true,false</returns>
        private bool IsAdd(int intType, ref int intCount, ref int index)
        {
            int count = 0;
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i].Tag.ToString() == intType.ToString())
                {
                    count += 1;

                    if (sp1.Controls[i] is WaterLevel)
                    {
                        WaterLevel wl = (WaterLevel)sp1.Controls[i];
                        index = wl.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is CurrentSpeed)
                    {
                        CurrentSpeed cs = (CurrentSpeed)sp1.Controls[i];
                        index = cs.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Flowmeters)
                    {
                        Flowmeters f = (Flowmeters)sp1.Controls[i];
                        index = f.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Flowmeters1)
                    {
                        Flowmeters1 f1 = (Flowmeters1)sp1.Controls[i];
                        index = f1.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                    {
                        WaterLevelAndCurrentSpeed wc = (WaterLevelAndCurrentSpeed)sp1.Controls[i];
                        index = wc.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is GatePosition)
                    {
                        GatePosition gp = (GatePosition)sp1.Controls[i];
                        index = gp.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Camera)
                    {
                        Camera c = (Camera)sp1.Controls[i];
                        index = c.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Video)
                    {
                        Video v = (Video)sp1.Controls[i];
                        index = v.cbbType.SelectedIndex;
                    }

                    if (index == 0)
                    {
                        index = 1;
                    }
                    else
                    {
                        index = 0;
                    }
                }
            }
            intCount = count;

            switch (intType)
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 6:
                case 7:
                    if (count >= 2)
                    {
                        return false;
                    }
                    return true;
                case 10:
                case 11:
                    if (count >= 8)
                    {
                        return false;
                    }
                    return true;
                default:
                    if (count >= 1)
                    {
                        return false;
                    }
                    return true;
            }
        }

        /// <summary>
        /// 判断是否存在相同类型的设备
        /// </summary>
        /// <param name="intType">设备类型</param>
        /// <param name="intSeq">设备序号</param>
        /// <returns>设备标识</returns>
        public int IsContains(int intType, int intSeq)
        {
            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i].Tag.ToString() == intType.ToString() && sp1.Controls[i].TabIndex != intSeq)
                {
                    if (sp1.Controls[i] is WaterLevel)
                    {
                        WaterLevel wl = (WaterLevel)sp1.Controls[i];
                        return wl.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is CurrentSpeed)
                    {
                        CurrentSpeed cs = (CurrentSpeed)sp1.Controls[i];
                        return cs.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Flowmeters)
                    {
                        Flowmeters f = (Flowmeters)sp1.Controls[i];
                        return f.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is Flowmeters1)
                    {
                        Flowmeters1 f1 = (Flowmeters1)sp1.Controls[i];
                        return f1.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                    {
                        WaterLevelAndCurrentSpeed wc = (WaterLevelAndCurrentSpeed)sp1.Controls[i];
                        return wc.cbbType.SelectedIndex;
                    }

                    if (sp1.Controls[i] is GatePosition)
                    {
                        GatePosition gp = (GatePosition)sp1.Controls[i];
                        return gp.cbbType.SelectedIndex;
                    }
                }
            }
            return -1;
        }

        private int GetItemIndex(ComboBoxEdit cbb, int intValue)
        {
            for (int i = 0; i < cbb.Properties.Items.Count; i++)
            {
                if ((cbb.Properties.Items[i] as ListItem).Value == intValue)
                {
                    return i;
                }
            }
            return -1;
        }

        public StructData.RtuConfigInfo DefaultConfig()
        {
            StructData.RtuConfigInfo rtuConfigInfo = (StructData.RtuConfigInfo)Protocol.BytesToStuct(new byte[paraDataLength], typeof(StructData.RtuConfigInfo));
            //基本配置
            rtuConfigInfo.StationType = 0;
            rtuConfigInfo.StationNo = new byte[5];
            rtuConfigInfo.StationName = new byte[62];
            rtuConfigInfo.ReportingCycle = 5;
            rtuConfigInfo.DataSaveCycel = 2;
            rtuConfigInfo.PreheatTime = 30;
            rtuConfigInfo.HeartbeatCycel = 10;
            rtuConfigInfo.WorkMode = 0;
            rtuConfigInfo.TimingReport = 0;
            rtuConfigInfo.HourReport = 0;
            rtuConfigInfo.AlarmCount = 1;
            rtuConfigInfo.AutoTiming = 0;
            rtuConfigInfo.ModbusSlaveAddr = 1;
            rtuConfigInfo.Function_485_3 = 0;
            rtuConfigInfo.Volt_work_min = 0;

            //以太网配置
            rtuConfigInfo.EthernetStatus = 0;
            rtuConfigInfo.EthernetDHCP = 0;

            for (int i = 0; i < 4; i++)
            {
                rtuConfigInfo.EthernetIP[i] = 0;
                rtuConfigInfo.EthernetGateway[i] = 0;
                rtuConfigInfo.EthernetNetmask[i] = 0;
                rtuConfigInfo.EthernetDNS[i] = 0;
                rtuConfigInfo.EthernetBackupDNS[i] = 0;
            }
            rtuConfigInfo.EthernetResetTime = 12;

            for (int i = 0; i < 4; i++)
            {
                rtuConfigInfo.CentralStationIP1[i] = 0;
                rtuConfigInfo.CentralStationIP2[i] = 0;
                rtuConfigInfo.CentralStationIP3[i] = 0;
                rtuConfigInfo.CentralStationIP4[i] = 0;
                rtuConfigInfo.CentralStationIP5[i] = 0;
            }

            byte[] bytes = new byte[2];
            bytes[0] = 0;
            bytes[1] = 0;
            rtuConfigInfo.CentralStationPort1[1] = bytes[0];
            rtuConfigInfo.CentralStationPort1[0] = bytes[1];
            rtuConfigInfo.CentralStationPort2[1] = bytes[0];
            rtuConfigInfo.CentralStationPort2[0] = bytes[1];
            rtuConfigInfo.CentralStationPort3[1] = bytes[0];
            rtuConfigInfo.CentralStationPort3[0] = bytes[1];
            rtuConfigInfo.CentralStationPort4[1] = bytes[0];
            rtuConfigInfo.CentralStationPort4[0] = bytes[1];
            rtuConfigInfo.CentralStationPort5[1] = bytes[0];
            rtuConfigInfo.CentralStationPort5[0] = bytes[1];

            rtuConfigInfo.CentralStationBackupPort1[1] = bytes[0];
            rtuConfigInfo.CentralStationBackupPort1[0] = bytes[1];
            rtuConfigInfo.CentralStationBackupPort2[1] = bytes[0];
            rtuConfigInfo.CentralStationBackupPort2[0] = bytes[1];
            rtuConfigInfo.CentralStationBackupPort3[1] = bytes[0];
            rtuConfigInfo.CentralStationBackupPort3[0] = bytes[1];
            rtuConfigInfo.CentralStationBackupPort4[1] = bytes[0];
            rtuConfigInfo.CentralStationBackupPort4[0] = bytes[1];

            rtuConfigInfo.CentralStationAddr[0] = 0;
            rtuConfigInfo.CentralStationAddr[1] = 0;
            rtuConfigInfo.CentralStationAddr[2] = 0;
            rtuConfigInfo.CentralStationAddr[3] = 0;

            rtuConfigInfo.CentralStationPassward1[1] = bytes[0];
            rtuConfigInfo.CentralStationPassward1[0] = bytes[1];
            rtuConfigInfo.CentralStationPassward2[1] = bytes[0];
            rtuConfigInfo.CentralStationPassward2[0] = bytes[1];
            rtuConfigInfo.CentralStationPassward3[1] = bytes[0];
            rtuConfigInfo.CentralStationPassward3[0] = bytes[1];
            rtuConfigInfo.CentralStationPassward4[1] = bytes[0];
            rtuConfigInfo.CentralStationPassward4[0] = bytes[1];

            rtuConfigInfo.CentralStationPhone1 = string.Empty.PadRight(13, '\0').ToCharArray();
            rtuConfigInfo.CentralStationPhone2 = string.Empty.PadRight(13, '\0').ToCharArray();
            rtuConfigInfo.CentralStationPhone3 = string.Empty.PadRight(13, '\0').ToCharArray();

            rtuConfigInfo.CentralStationTransportProtocol[0] = 0;
            rtuConfigInfo.CentralStationTransportProtocol[1] = 0;
            rtuConfigInfo.CentralStationTransportProtocol[2] = 0;

            rtuConfigInfo.CentralStationReportProtocol[0] = 0;
            rtuConfigInfo.CentralStationReportProtocol[1] = 0;
            rtuConfigInfo.CentralStationReportProtocol[2] = 0;

            rtuConfigInfo.CentralStationHardwareInterface[0] = 0;
            rtuConfigInfo.CentralStationHardwareInterface[1] = 0;
            rtuConfigInfo.CentralStationHardwareInterface[2] = 0;

            rtuConfigInfo.CentralStationVpnEnable = 0;
            rtuConfigInfo.CentralStationVpnPoint = string.Empty.PadRight(16, '\0').ToCharArray();
            rtuConfigInfo.CentralStationVpnName = string.Empty.PadRight(16, '\0').ToCharArray();
            rtuConfigInfo.CentralStationVpnPassword = string.Empty.PadRight(16, '\0').ToCharArray();
            rtuConfigInfo.CentralStationRemoteVpnEnable = 0;

            rtuConfigInfo.WaterLevel_Enable = 0;
            rtuConfigInfo.CurrentSpeed_Enable = 0;
            rtuConfigInfo.WaterFlow_Enable = 0;
            rtuConfigInfo.GatePosition_Enable = 0;
            rtuConfigInfo.RainFall_Enable = 0;
            rtuConfigInfo.WaterQuality_Enable[0] = 0;
            rtuConfigInfo.WaterQuality_Enable[1] = 0;
            rtuConfigInfo.Camera_Enable = 0;
            rtuConfigInfo.Video_Enable = 0;
            rtuConfigInfo.WaterFlowCount_Enable = 0;
            rtuConfigInfo.WaterTemperature_Enable = 0;

            rtuConfigInfo.WaterLevelHight1 = new byte[4];
            rtuConfigInfo.WaterLevelHight2 = new byte[4];
            rtuConfigInfo.WaterLevel_Addr[0] = 0;
            rtuConfigInfo.WaterLevel_Addr[1] = 0;
            rtuConfigInfo.WaterLevelDeviceSelect[0] = 0;
            rtuConfigInfo.WaterLevelDeviceSelect[1] = 0;
            rtuConfigInfo.WaterBaseLevel1 = new byte[4];
            rtuConfigInfo.WaterBaseLevel2 = new byte[4];
            rtuConfigInfo.WaterCorrectionLevel1 = new byte[4];
            rtuConfigInfo.WaterCorrectionLevel2 = new byte[4];
            rtuConfigInfo.WaterCorrParame1 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterCorrParame2 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterLevelHAlarm1 = new byte[4];
            rtuConfigInfo.WaterLevelHAlarm2 = new byte[4];
            rtuConfigInfo.WaterLevelLAlarm1 = new byte[4];
            rtuConfigInfo.WaterLevelLAlarm2 = new byte[4];
            rtuConfigInfo.WaterLevelAlarmH1 = new byte[4];
            rtuConfigInfo.WaterLevelAlarmH2 = new byte[4];
            rtuConfigInfo.WaterLevelAlarmL1 = new byte[4];
            rtuConfigInfo.WaterLevelAlarmL2 = new byte[4];
            rtuConfigInfo.WaterLevelChangeAlarm = new byte[2];
            rtuConfigInfo.WaterFilter = new byte[2];
            rtuConfigInfo.WaterFilterParam = new byte[2];

            rtuConfigInfo.CurrentSpeedDeviceSelect = new byte[2];
            rtuConfigInfo.CurrentSpeed_Addr = new byte[2];
            rtuConfigInfo.CurrentSpeedDeviation1 = new byte[4];
            rtuConfigInfo.CurrentSpeedDeviation2 = new byte[4];
            rtuConfigInfo.CurrentSpeedRatio1 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.CurrentSpeedRatio2 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();

            rtuConfigInfo.WaterFlowHeight1 = new byte[4];
            rtuConfigInfo.WaterFlowHeight2 = new byte[4];
            rtuConfigInfo.WaterFlow_Addr = new byte[2];
            rtuConfigInfo.WaterFlowDeviceSelect = new byte[2];
            rtuConfigInfo.WaterFlowWaterLevelDeviation1 = new byte[4];
            rtuConfigInfo.WaterFlowWaterLevelRatio1 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterFlowCurrentSpeedDeviation1 = new byte[4];
            rtuConfigInfo.WaterFlowCurrentSpeedRatio1 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterFlowWaterLevelDeviation2 = new byte[4];
            rtuConfigInfo.WaterFlowWaterLevelRatio2 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterFlowCurrentSpeedDeviation2 = new byte[4];
            rtuConfigInfo.WaterFlowCurrentSpeedRatio2 = BitConverter.GetBytes(1 * 10000).Reverse<byte>().ToArray();

            rtuConfigInfo.GatePosition_Addr = new byte[2];
            rtuConfigInfo.GatePositionZeroing1 = new byte[4];
            rtuConfigInfo.GatePositionZeroing2 = new byte[4];
            rtuConfigInfo.GatePositionDirection = new byte[2];
            rtuConfigInfo.GatePositionDeviceSelect = new byte[2];

            rtuConfigInfo.RainResolutionRatio = 0;
            rtuConfigInfo.RainFallDeviceSelect = 0;
            rtuConfigInfo.RainAlarm = 0;
            //rtuConfigInfo.RainTimeReport = 0;
            rtuConfigInfo.DayRain = new byte[4];
            rtuConfigInfo.TotalRain = new byte[4];

            rtuConfigInfo.WaterQuality_PH_Addr = 0;
            rtuConfigInfo.WaterQuality_Rjy_Addr = 0;
            rtuConfigInfo.WaterQuality_Ddl_Addr = 0;
            rtuConfigInfo.WaterQuality_Zd1000_Addr = 0;
            rtuConfigInfo.WaterQuality_Zd4000_Addr = 0;
            rtuConfigInfo.WaterQuality_COD_Addr = 0;
            rtuConfigInfo.WaterQuality_Ad_Addr = 0;
            rtuConfigInfo.WaterQuality_Yl_Addr = 0;
            rtuConfigInfo.WaterQuality_Sz_Addr = 0;

            rtuConfigInfo.CameraDeviceSelect = new byte[2];
            rtuConfigInfo.Camera_Addr = new byte[2];
            rtuConfigInfo.Camera_AcquisitionCycle1 = BitConverter.GetBytes(10).Reverse<byte>().ToArray();
            rtuConfigInfo.Camera_AcquisitionCycle2 = BitConverter.GetBytes(10).Reverse<byte>().ToArray();
            rtuConfigInfo.Camera_Overlying = new byte[2];
            rtuConfigInfo.Camera_TimeInterval = new byte[2];
            rtuConfigInfo.Camera_Cache = new byte[2];
            rtuConfigInfo.Camera_PicAck = new byte[2];
            rtuConfigInfo.Camera_Hours1[0] = 0;
            rtuConfigInfo.Camera_Hours1[1] = 0;
            rtuConfigInfo.Camera_Hours1[2] = 0;
            rtuConfigInfo.Camera_Hours2[0] = 0;
            rtuConfigInfo.Camera_Hours2[1] = 0;
            rtuConfigInfo.Camera_Hours2[2] = 0;

            rtuConfigInfo.VideoDeviceSelect = new byte[2];
            rtuConfigInfo.VideoOverlayUpdateTime[0] = 5;
            rtuConfigInfo.VideoOverlayUpdateTime[1] = 5;
            rtuConfigInfo.VideoIP1[0] = 0;
            rtuConfigInfo.VideoIP1[1] = 0;
            rtuConfigInfo.VideoIP1[2] = 0;
            rtuConfigInfo.VideoIP1[3] = 0;
            rtuConfigInfo.VideoUserName1 = string.Empty.PadRight(20, '\0').ToCharArray();
            rtuConfigInfo.VideoPassWord1 = string.Empty.PadRight(20, '\0').ToCharArray();
            rtuConfigInfo.VideoPort1 = BitConverter.GetBytes(80).Reverse<byte>().ToArray();
            rtuConfigInfo.VideoContentSelection1[0] = 0;
            rtuConfigInfo.VideoContentSelection1[1] = 0;
            rtuConfigInfo.VideoContentSelection1[2] = 0;
            rtuConfigInfo.VideoContentSelection1[3] = 0;
            rtuConfigInfo.VideoOverlayName11 = new byte[40];
            rtuConfigInfo.VideoOverlayName12 = new byte[40];
            rtuConfigInfo.VideoOverlayName13 = new byte[40];
            rtuConfigInfo.VideoOverlayName14 = new byte[40];
            rtuConfigInfo.VideoContentCoordinate11_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate11_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate12_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate12_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate13_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate13_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate14_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate14_Y = new byte[2];
            rtuConfigInfo.VideoIP2[0] = 0;
            rtuConfigInfo.VideoIP2[1] = 0;
            rtuConfigInfo.VideoIP2[2] = 0;
            rtuConfigInfo.VideoIP2[3] = 0;
            rtuConfigInfo.VideoUserName2 = string.Empty.PadRight(20, '\0').ToCharArray();
            rtuConfigInfo.VideoPassWord2 = string.Empty.PadRight(20, '\0').ToCharArray();
            rtuConfigInfo.VideoPort2 = BitConverter.GetBytes(80).Reverse<byte>().ToArray();
            rtuConfigInfo.VideoContentSelection2[0] = 0;
            rtuConfigInfo.VideoContentSelection2[1] = 0;
            rtuConfigInfo.VideoContentSelection2[2] = 0;
            rtuConfigInfo.VideoContentSelection2[3] = 0;
            rtuConfigInfo.VideoOverlayName21 = new byte[40];
            rtuConfigInfo.VideoOverlayName22 = new byte[40];
            rtuConfigInfo.VideoOverlayName23 = new byte[40];
            rtuConfigInfo.VideoOverlayName24 = new byte[40];
            rtuConfigInfo.VideoContentCoordinate21_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate21_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate22_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate22_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate23_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate23_Y = new byte[2];
            rtuConfigInfo.VideoContentCoordinate24_X = new byte[2];
            rtuConfigInfo.VideoContentCoordinate24_Y = new byte[2];

            rtuConfigInfo.WaterFlowCountSelect = new byte[2];
            rtuConfigInfo.WaterFlowSectionSelect = new byte[2];
            rtuConfigInfo.WaterFlowCorrection1 = BitConverter.GetBytes(1 * 1000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterFlowShowType[0] = 0;
            rtuConfigInfo.WaterFlowAccuracy[0] = 0;
            rtuConfigInfo.WaterFlowCumulativeSwitch[0] = 0;
            rtuConfigInfo.WaterFlowTotal1 = new byte[4];
            rtuConfigInfo.WaterFlowTwoway[0] = 0;
            rtuConfigInfo.WaterFlowWaveFiltering[0] = 0;
            rtuConfigInfo.WaterFlowCorrection2 = BitConverter.GetBytes(1 * 1000).Reverse<byte>().ToArray();
            rtuConfigInfo.WaterFlowShowType[1] = 0;
            rtuConfigInfo.WaterFlowAccuracy[1] = 0;
            rtuConfigInfo.WaterFlowCumulativeSwitch[1] = 0;
            rtuConfigInfo.WaterFlowTotal2 = new byte[4];
            rtuConfigInfo.WaterFlowTwoway[1] = 0;
            rtuConfigInfo.WaterFlowWaveFiltering[1] = 0;
            rtuConfigInfo.WaterFlowSiltationDepth1 = new byte[2];
            rtuConfigInfo.WaterFlowSiltationDepth2 = new byte[2];
            rtuConfigInfo.WaterFlowParameter11 = new byte[2];
            rtuConfigInfo.WaterFlowParameter12 = new byte[2];
            rtuConfigInfo.WaterFlowParameter13 = new byte[2];
            rtuConfigInfo.WaterFlowParameter14 = new byte[2];
            rtuConfigInfo.WaterFlowParameter21 = new byte[2];
            rtuConfigInfo.WaterFlowParameter22 = new byte[2];
            rtuConfigInfo.WaterFlowParameter23 = new byte[2];
            rtuConfigInfo.WaterFlowParameter24 = new byte[2];
            rtuConfigInfo.WaterFlowSectionHeightResolution = new byte[2];
            rtuConfigInfo.FlowmeterBaseLevel1 = new byte[4];
            rtuConfigInfo.FlowmeterBaseLevel2 = new byte[4];

            byte[] b = Protocol.StructToBytes(rtuConfigInfo);
            return rtuConfigInfo;
        }

        /// <summary>
        /// 初始设备配置
        /// </summary>
        public void SetConfig(StructData.RtuConfigInfo rtuConfig)
        {
            try
            {
                chkJs1.Checked = false;
                chkJs2.Checked = false;
                rtuConfigInfo = rtuConfig;
                //基本配置
                cbb1.SelectedIndex = rtuConfigInfo.StationType;
                txtBox1.Text = Protocol.ConvertData(rtuConfigInfo.StationNo).Replace("\0", "");
                txtBox2.Text = System.Text.Encoding.Default.GetString(rtuConfigInfo.StationName).Replace("\0", "");
                cbbNud1.SelectedIndex = GetItemIndex(cbbNud1, rtuConfigInfo.ReportingCycle);
                cbbNud2.SelectedIndex = GetItemIndex(cbbNud2, rtuConfigInfo.DataSaveCycel);
                nud6.Value = rtuConfigInfo.PreheatTime;
                nud3.Value = rtuConfigInfo.HeartbeatCycel;
                cbb2.SelectedIndex = rtuConfigInfo.WorkMode;
                nud4.SelectedIndex = rtuConfigInfo.TimingReport;
                cbb3.SelectedIndex = rtuConfigInfo.HourReport;
                nud5.SelectedIndex = rtuConfigInfo.AlarmCount;
                cbb4.SelectedIndex = rtuConfigInfo.AutoTiming;
                nud7.Value = rtuConfigInfo.ModbusSlaveAddr == 0 ? 1: rtuConfigInfo.ModbusSlaveAddr;
                cbb7.SelectedIndex = rtuConfigInfo.Function_485_3;
                cbb8.SelectedIndex = rtuConfigInfo.RainTimeReport;
                txtBox3.Text = (rtuConfigInfo.Volt_work_min / 10).ToString();

                //以太网配置
                cbbYt1.SelectedIndex = rtuConfigInfo.EthernetStatus;
                cbbYt2.SelectedIndex = rtuConfigInfo.EthernetDHCP;
                ipAddressInput1.Value = rtuConfigInfo.EthernetIP[0].ToString() + "." + rtuConfigInfo.EthernetIP[1].ToString() + "." + rtuConfigInfo.EthernetIP[2].ToString() + "." + rtuConfigInfo.EthernetIP[3].ToString();
                ipAddressInput2.Value = rtuConfigInfo.EthernetGateway[0].ToString() + "." + rtuConfigInfo.EthernetGateway[1].ToString() + "." + rtuConfigInfo.EthernetGateway[2].ToString() + "." + rtuConfigInfo.EthernetGateway[3].ToString();
                ipAddressInput3.Value = rtuConfigInfo.EthernetNetmask[0].ToString() + "." + rtuConfigInfo.EthernetNetmask[1].ToString() + "." + rtuConfigInfo.EthernetNetmask[2].ToString() + "." + rtuConfigInfo.EthernetNetmask[3].ToString();
                ipAddressInput4.Value = rtuConfigInfo.EthernetDNS[0].ToString() + "." + rtuConfigInfo.EthernetDNS[1].ToString() + "." + rtuConfigInfo.EthernetDNS[2].ToString() + "." + rtuConfigInfo.EthernetDNS[3].ToString();
                ipAddressInput5.Value = rtuConfigInfo.EthernetBackupDNS[0].ToString() + "." + rtuConfigInfo.EthernetBackupDNS[1].ToString() + "." + rtuConfigInfo.EthernetBackupDNS[2].ToString() + "." + rtuConfigInfo.EthernetBackupDNS[3].ToString();
                nudYt1.Value = rtuConfigInfo.EthernetResetTime;

                //中心站配置
                ip1.Value = rtuConfigInfo.CentralStationIP1[0].ToString() + "." + rtuConfigInfo.CentralStationIP1[1].ToString() + "." + rtuConfigInfo.CentralStationIP1[2].ToString() + "." + rtuConfigInfo.CentralStationIP1[3].ToString();
                ip2.Value = rtuConfigInfo.CentralStationIP2[0].ToString() + "." + rtuConfigInfo.CentralStationIP2[1].ToString() + "." + rtuConfigInfo.CentralStationIP2[2].ToString() + "." + rtuConfigInfo.CentralStationIP2[3].ToString();
                ip3.Value = rtuConfigInfo.CentralStationIP3[0].ToString() + "." + rtuConfigInfo.CentralStationIP3[1].ToString() + "." + rtuConfigInfo.CentralStationIP3[2].ToString() + "." + rtuConfigInfo.CentralStationIP3[3].ToString();
                ip4.Value = rtuConfigInfo.CentralStationIP4[0].ToString() + "." + rtuConfigInfo.CentralStationIP4[1].ToString() + "." + rtuConfigInfo.CentralStationIP4[2].ToString() + "." + rtuConfigInfo.CentralStationIP4[3].ToString();
                ip5.Value = rtuConfigInfo.CentralStationIP5[0].ToString() + "." + rtuConfigInfo.CentralStationIP5[1].ToString() + "." + rtuConfigInfo.CentralStationIP5[2].ToString() + "." + rtuConfigInfo.CentralStationIP5[3].ToString();
                nud11.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPort1[0], rtuConfigInfo.CentralStationPort1[1]);
                nud21.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPort2[0], rtuConfigInfo.CentralStationPort2[1]);
                nud31.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPort3[0], rtuConfigInfo.CentralStationPort3[1]);
                nud41.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPort4[0], rtuConfigInfo.CentralStationPort4[1]);
                nud51.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPort5[0], rtuConfigInfo.CentralStationPort5[1]);
                nud12.Value = Common.BytesToShort(rtuConfigInfo.CentralStationBackupPort1[0], rtuConfigInfo.CentralStationBackupPort1[1]);
                nud22.Value = Common.BytesToShort(rtuConfigInfo.CentralStationBackupPort2[0], rtuConfigInfo.CentralStationBackupPort2[1]);
                nud32.Value = Common.BytesToShort(rtuConfigInfo.CentralStationBackupPort3[0], rtuConfigInfo.CentralStationBackupPort3[1]);
                nud42.Value = Common.BytesToShort(rtuConfigInfo.CentralStationBackupPort4[0], rtuConfigInfo.CentralStationBackupPort4[1]);
                nud14.Value = rtuConfigInfo.CentralStationAddr[0];
                nud24.Value = rtuConfigInfo.CentralStationAddr[1];
                nud34.Value = rtuConfigInfo.CentralStationAddr[2];
                nud44.Value = rtuConfigInfo.CentralStationAddr[3];
                nud15.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPassward1[0], rtuConfigInfo.CentralStationPassward1[1]);
                nud25.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPassward2[0], rtuConfigInfo.CentralStationPassward2[1]);
                nud35.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPassward3[0], rtuConfigInfo.CentralStationPassward3[1]);
                nud45.Value = Common.BytesToShort(rtuConfigInfo.CentralStationPassward4[0], rtuConfigInfo.CentralStationPassward4[1]);
                txtNo1.Text = new string(rtuConfigInfo.CentralStationPhone1).Replace("\0", "");
                txtNo2.Text = new string(rtuConfigInfo.CentralStationPhone2).Replace("\0", "");
                txtNo3.Text = new string(rtuConfigInfo.CentralStationPhone3).Replace("\0", "");
                cbb11.SelectedIndex = rtuConfigInfo.CentralStationTransportProtocol[0];
                cbb21.SelectedIndex = rtuConfigInfo.CentralStationTransportProtocol[1];
                cbb31.SelectedIndex = rtuConfigInfo.CentralStationTransportProtocol[2];
                cbb12.SelectedIndex = rtuConfigInfo.CentralStationReportProtocol[0];
                cbb22.SelectedIndex = rtuConfigInfo.CentralStationReportProtocol[1];
                cbb32.SelectedIndex = rtuConfigInfo.CentralStationReportProtocol[2];
                cbb13.SelectedIndex = rtuConfigInfo.CentralStationHardwareInterface[0];
                cbb23.SelectedIndex = rtuConfigInfo.CentralStationHardwareInterface[1];
                cbb33.SelectedIndex = rtuConfigInfo.CentralStationHardwareInterface[2];
                cbb5.SelectedIndex = rtuConfigInfo.CentralStationVpnEnable;
                txtBox51.Text = new string(rtuConfigInfo.CentralStationVpnPoint).Replace("\0", "");
                txtBox52.Text = new string(rtuConfigInfo.CentralStationVpnName).Replace("\0", "");
                txtBox53.Text = new string(rtuConfigInfo.CentralStationVpnPassword).Replace("\0", "");
                cbb6.SelectedIndex = rtuConfigInfo.CentralStationRemoteVpnEnable;

                //4-20mA设置
                c1.SelectedIndex = rtuConfigInfo.IoutputModule_Enable;
                c2.Value = rtuConfigInfo.IoutputModule_Addr;
                c3.SelectedIndex = rtuConfigInfo.IoutputModule_DeviceSelect;

                c11.SelectedIndex = rtuConfigInfo.IoutputModule_DataSelect[0];
                c12.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_4mAValue1.Reverse<byte>().ToArray(), 0) / 1000.0);
                c13.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_20mAValue1.Reverse<byte>().ToArray(), 0) / 1000.0);
                c21.SelectedIndex = rtuConfigInfo.IoutputModule_DataSelect[1];
                c22.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_4mAValue2.Reverse<byte>().ToArray(), 0) / 1000.0);
                c23.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_20mAValue2.Reverse<byte>().ToArray(), 0) / 1000.0);
                c31.SelectedIndex = rtuConfigInfo.IoutputModule_DataSelect[2];
                c32.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_4mAValue3.Reverse<byte>().ToArray(), 0) / 1000.0);
                c33.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_20mAValue3.Reverse<byte>().ToArray(), 0) / 1000.0);
                c41.SelectedIndex = rtuConfigInfo.IoutputModule_DataSelect[3];
                c42.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_4mAValue4.Reverse<byte>().ToArray(), 0) / 1000.0);
                c43.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.IoutputModule_20mAValue4.Reverse<byte>().ToArray(), 0) / 1000.0);

                d1.SelectedIndex = rtuConfigInfo.Iinput_Enable;
                d11.SelectedIndex = rtuConfigInfo.Iin_DataSelect[0];
                d12.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.Iin_4mAValue1.Reverse<byte>().ToArray(), 0) / 1000.0);
                d13.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.Iin_20mAValue1.Reverse<byte>().ToArray(), 0) / 1000.0);
                d21.SelectedIndex = rtuConfigInfo.Iin_DataSelect[1];
                d22.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.Iin_4mAValue2.Reverse<byte>().ToArray(), 0) / 1000.0);
                d23.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.Iin_20mAValue2.Reverse<byte>().ToArray(), 0) / 1000.0);

                //设备配置
                listDevice1.Clear();
                listDevice2.Clear();
                listWaterTemperature.Clear();

                foreach (Control item in sp1.Controls)
                {
                    item.Dispose();
                }

                sp1.Controls.Clear();
                //水位计开关
                byte byteWe = rtuConfigInfo.WaterLevel_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)//水位计1
                {
                    WaterLevel wl = new WaterLevel(this);
                    wl.InitValue(0, 0, rtuConfigInfo.WaterLevelDeviceSelect[0]);
                    wl.SetValue();
                    sp1.Controls.Add(wl);
                }

                if (Common.GetIntBit(byteWe, 1) == 1)//水位计2
                {
                    WaterLevel wl = new WaterLevel(this);
                    wl.InitValue(0, 1, rtuConfigInfo.WaterLevelDeviceSelect[1]);
                    wl.SetValue();
                    sp1.Controls.Add(wl);
                }

                //流速仪开关
                byteWe = rtuConfigInfo.CurrentSpeed_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)//流速1
                {
                    CurrentSpeed cs = new CurrentSpeed(this);
                    cs.InitValue(1, 0, rtuConfigInfo.CurrentSpeedDeviceSelect[0]);
                    cs.SetValue();
                    sp1.Controls.Add(cs);
                }

                if (Common.GetIntBit(byteWe, 1) == 1)//流速2
                {
                    CurrentSpeed cs = new CurrentSpeed(this);
                    cs.InitValue(1, 1, rtuConfigInfo.CurrentSpeedDeviceSelect[1]);
                    cs.SetValue();
                    sp1.Controls.Add(cs);
                }

                //流量计开关
                byteWe = rtuConfigInfo.WaterFlow_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    int selectIndex = rtuConfigInfo.WaterFlowDeviceSelect[0];
                    if (selectIndex == 2 || selectIndex == 3)
                    {
                        WaterLevelAndCurrentSpeed wc = new WaterLevelAndCurrentSpeed(this);
                        wc.InitValue(2, 0, selectIndex);
                        wc.SetValue();
                        sp1.Controls.Add(wc);
                    }
                    else if (selectIndex == 1)
                    {
                        Flowmeters1 fl1 = new Flowmeters1(this);
                        fl1.InitValue(2, 0, selectIndex);
                        fl1.SetValue();
                        sp1.Controls.Add(fl1);
                    }
                    else
                    {
                        Flowmeters fl = new Flowmeters(this);
                        fl.InitValue(2, 0, selectIndex);
                        fl.SetValue();
                        sp1.Controls.Add(fl);
                    }
                }

                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    int selectIndex = rtuConfigInfo.WaterFlowDeviceSelect[1];
                    if (selectIndex == 2 || selectIndex == 3)
                    {
                        WaterLevelAndCurrentSpeed wc = new WaterLevelAndCurrentSpeed(this);
                        wc.InitValue(2, 1, selectIndex);
                        wc.SetValue();
                        sp1.Controls.Add(wc);
                    }
                    else if (selectIndex == 1)
                    {
                        Flowmeters1 fl1 = new Flowmeters1(this);
                        fl1.InitValue(2, 1, selectIndex);
                        fl1.SetValue();
                        sp1.Controls.Add(fl1);
                    }
                    else
                    {
                        Flowmeters fl = new Flowmeters(this);
                        fl.InitValue(2, 1, selectIndex);
                        fl.SetValue();
                        sp1.Controls.Add(fl);
                    }
                }

                //闸位计开关
                byteWe = rtuConfigInfo.GatePosition_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    GatePosition gp = new GatePosition(this);
                    gp.InitValue(3, 0, rtuConfigInfo.GatePositionDeviceSelect[0]);
                    gp.SetValue();
                    sp1.Controls.Add(gp);
                }

                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    GatePosition gp = new GatePosition(this);
                    gp.InitValue(3, 1, rtuConfigInfo.GatePositionDeviceSelect[1]);
                    gp.SetValue();
                    sp1.Controls.Add(gp);
                }

                //雨量开关
                byteWe = rtuConfigInfo.RainFall_Enable;
                if (byteWe == 1)
                {
                    RainFall gp = new RainFall();
                    gp.InitValue(4, 0, rtuConfigInfo.RainFallDeviceSelect);
                    gp.SetValue();
                    sp1.Controls.Add(gp);
                }

                //水质 在线PH传感器开关
                byteWe = rtuConfigInfo.WaterQuality_Enable[0];
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 0);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线溶解氧传感器开关
                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 1);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线电导率传感器开关
                if (Common.GetIntBit(byteWe, 2) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 2);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线浊度传感器(1000NTU)开关
                if (Common.GetIntBit(byteWe, 3) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 3);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线浊度传感器(4000NTU)开关
                if (Common.GetIntBit(byteWe, 4) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 4);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线COD传感器开关
                if (Common.GetIntBit(byteWe, 5) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 5);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线氨氮传感器开关
                if (Common.GetIntBit(byteWe, 6) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 6);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线余氯传感器开关
                if (Common.GetIntBit(byteWe, 7) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 7);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线多参数水质传感器(DX-W100-1)开关
                if (Common.GetIntBit(rtuConfigInfo.WaterQuality_Enable[1], 0) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 8);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线多参数水质传感器(DX-Multipro-G5)开关
                if (Common.GetIntBit(rtuConfigInfo.WaterQuality_Enable[1], 1) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 9);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线多参数水质传感器(BSM-2)开关
                if (Common.GetIntBit(rtuConfigInfo.WaterQuality_Enable[1], 2) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 10);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //水质 在线ORP传感器开关
                if (Common.GetIntBit(rtuConfigInfo.WaterQuality_Enable[1], 3) == 1)
                {
                    WaterQuality wq = new WaterQuality(this);
                    wq.InitValue(5, 11);
                    wq.SetValue();
                    sp1.Controls.Add(wq);
                }

                //相机开关
                byteWe = rtuConfigInfo.Camera_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    Camera c = new Camera();
                    c.InitValue(6, 0, rtuConfigInfo.CameraDeviceSelect[0]);
                    c.SetValue();
                    sp1.Controls.Add(c);
                }

                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    Camera c = new Camera();
                    c.InitValue(6, 1, rtuConfigInfo.CameraDeviceSelect[1]);
                    c.SetValue();
                    sp1.Controls.Add(c);
                }

                //摄像头开关
                byteWe = rtuConfigInfo.Video_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    Video v = new Video();
                    v.InitValue(7, 0, rtuConfigInfo.VideoDeviceSelect[0]);
                    v.SetValue();
                    sp1.Controls.Add(v);
                }

                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    Video v = new Video();
                    v.InitValue(7, 1, rtuConfigInfo.VideoDeviceSelect[1]);
                    v.SetValue();
                    sp1.Controls.Add(v);
                }

                //多流速开关
                byteWe = rtuConfigInfo.MultiSpeed_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)//多流速
                {
                    WaterLevelAndCurrentSpeeds wc = new WaterLevelAndCurrentSpeeds(this);
                    wc.InitValue(9, 0, rtuConfigInfo.MultiSpeedDeviceSelect);
                    sp1.Controls.Add(wc);
                    wc.SetValue();
                    wc.SetNo(rtuConfigInfo.MultiSpeedWaterLevelDeviceSelect);
                }

                //土壤温湿度开关
                byteWe = rtuConfigInfo.SoilTempHumi_Enable;
                for (int i = 0; i < 8; i++)
                {
                    if (Common.GetIntBit(byteWe, i) == 1)
                    {
                        Soil s = new Soil(this);
                        s.InitValue(10, i, rtuConfigInfo.SoilTempHumi_Select[i]);
                        s.SetValue();
                        sp1.Controls.Add(s);
                    }
                }

                //渗压力开关
                byteWe = rtuConfigInfo.OsmoticPressure_Enable;
                for (int i = 0; i < 8; i++)
                {
                    if (Common.GetIntBit(byteWe, i) == 1)
                    {
                        OsmoticPressure s = new OsmoticPressure(this);
                        s.InitValue(11, i, rtuConfigInfo.OsmoticPressure_Select[i]);
                        s.SetValue();
                        sp1.Controls.Add(s);
                    }
                }

                //风速开关
                byteWe = rtuConfigInfo.WindSpeed_Enable;
                if (byteWe == 1)
                {
                    WindSpeed ws = new WindSpeed(this);
                    ws.InitValue(12, 0, rtuConfigInfo.WindSpeed_Select);
                    ws.SetValue();
                    sp1.Controls.Add(ws);
                }

                //风向开关
                byteWe = rtuConfigInfo.WindDir_Enable;
                if (byteWe == 1)
                {
                    WindDir wd = new WindDir(this);
                    wd.InitValue(12, 0, rtuConfigInfo.WindDir_Select);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }

                //大气温湿压开关
                byteWe = rtuConfigInfo.Atmosphere_Enable;
                if (byteWe == 1)
                {
                    Atmosphere wd = new Atmosphere(this);
                    wd.InitValue(12, 0, rtuConfigInfo.Atmosphere_Select);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }

                //气象站（七要素）开关
                byteWe = rtuConfigInfo.Multi_Weather_Enable;
                if (byteWe == 1)
                {
                    MeteorologicalStationSeven wd = new MeteorologicalStationSeven(this);
                    wd.InitValue(16, 0, 0);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }

                //PMgas开关
                byteWe = rtuConfigInfo.PmGas_Enable;
                if (byteWe == 1)
                {
                    PmGas wd = new PmGas(this);
                    wd.InitValue(15, 0, rtuConfigInfo.PmGas_Select);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }
                //pm2.5开关
                byteWe = rtuConfigInfo.Pm25_Enable;
                if (byteWe == 1)
                {
                    Pm25 wd = new Pm25(this);
                    wd.InitValue(15, 0, rtuConfigInfo.Pm25_Select);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }
                //pm10开关
                byteWe = rtuConfigInfo.Pm10_Enable;
                if (byteWe == 1)
                {
                    Pm10 wd = new Pm10(this);
                    wd.InitValue(15, 0, rtuConfigInfo.Pm10_Select);
                    wd.SetValue();
                    sp1.Controls.Add(wd);
                }

                InitFlowFs();
                //sp1.SuspendLayout();
                sp1.Refresh();
                //BindFlowList1();
                //BindFlowList2();

                //水温开关
                byteWe = rtuConfigInfo.WaterTemperature_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    WaterTemperature w = new WaterTemperature();
                    sp1.Controls.Add(w);
                    BindWaterTemperature();
                    w.InitValue(8, 0, 0);
                    w.SetValue();
                }

                ControlsSort();

                //流量积算开关
                byteWe = rtuConfigInfo.WaterFlowCount_Enable;
                if (Common.GetIntBit(byteWe, 0) == 1)
                {
                    cbbJs1.SelectedIndex = GetItemIndex(cbbJs1, rtuConfigInfo.WaterFlowCountSelect[0]);
                    cbbDm1.SelectedIndex = rtuConfigInfo.WaterFlowSectionSelect[0];
                    chkJs1.Checked = true;
                }
                else
                {
                    chkJs1.Checked = false;
                }

                if (Common.GetIntBit(byteWe, 1) == 1)
                {
                    cbbJs2.SelectedIndex = GetItemIndex(cbbJs2, rtuConfigInfo.WaterFlowCountSelect[1]);
                    cbbDm2.SelectedIndex = rtuConfigInfo.WaterFlowSectionSelect[1];
                    chkJs2.Checked = true;
                }
                else
                {
                    chkJs2.Checked = false;
                }
                //if (btnYc1.Visible)
                //{
                //    btnWaterLevelSetting.Location = new Point(1022, 23);
                //}
                //else
                //{
                //    btnWaterLevelSetting.Location = btnYc1.Location;
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void InitFlowFs()
        {
            //设备配置
            listDevice1.Clear();
            listDevice2.Clear();
            listWaterTemperature.Clear();

            for (int i = 0; i < sp1.Controls.Count; i++)
            {
                if (sp1.Controls[i] is WaterLevel)
                {
                    WaterLevel wl = sp1.Controls[i] as WaterLevel;
                    if (wl.cbbType.SelectedIndex == 0)//水位计1
                    {
                        if (!listDevice1.Contains("0"))
                        {
                            listDevice1.Add("0");
                        }
                        listWaterTemperature.Add("1");
                    }

                    if (wl.cbbType.SelectedIndex == 1)//水位计2
                    {
                        if (!listDevice2.Contains("0"))
                        {
                            listDevice2.Add("0");
                        }
                        listWaterTemperature.Add("2");
                    }
                }

                if (sp1.Controls[i] is CurrentSpeed)
                {
                    CurrentSpeed cs = sp1.Controls[i] as CurrentSpeed;
                    if (cs.cbbType.SelectedIndex == 0)//流速1
                    {
                        if (!listDevice1.Contains("1"))
                        {
                            listDevice1.Add("1");
                        }
                    }

                    if (cs.cbbType.SelectedIndex == 1)//流速2
                    {
                        if (!listDevice2.Contains("1"))
                        {
                            listDevice2.Add("1");
                        }
                    }
                }

                if (sp1.Controls[i] is Flowmeters)
                {
                    Flowmeters ft = sp1.Controls[i] as Flowmeters;
                    int selectIndex = ft.DeviceSelectNo;
                    if (ft.cbbType.SelectedIndex == 0)
                    {
                        if (selectIndex == 0 || selectIndex == 5)
                        {
                            if (!listDevice1.Contains("01"))
                            {
                                listDevice1.Add("01");
                            }
                        }
                        else
                        {
                            if (!listDevice1.Contains("2"))
                            {
                                listDevice1.Add("2");
                            }
                        }

                        if (!listWaterTemperature.Contains("3"))
                        {
                            listWaterTemperature.Add("3");
                        }
                    }

                    if (ft.cbbType.SelectedIndex == 1)
                    {
                        if (selectIndex == 0 || selectIndex == 5)
                        {
                            if (!listDevice2.Contains("01"))
                            {
                                listDevice2.Add("01");
                            }
                        }
                        else
                        {
                            if (!listDevice2.Contains("2"))
                            {
                                listDevice2.Add("2");
                            }
                        }

                        if (!listWaterTemperature.Contains("4"))
                        {
                            listWaterTemperature.Add("4");
                        }
                    }
                }

                if (sp1.Controls[i] is Flowmeters1)
                {
                    Flowmeters1 ft1 = sp1.Controls[i] as Flowmeters1;
                    if (ft1.cbbType.SelectedIndex == 0)
                    {
                        if (!listDevice1.Contains("0"))
                        {
                            listDevice1.Add("0");
                        }

                        if (!listWaterTemperature.Contains("3"))
                        {
                            listWaterTemperature.Add("3");
                        }
                    }

                    if (ft1.cbbType.SelectedIndex == 1)
                    {
                        if (!listDevice2.Contains("0"))
                        {
                            listDevice2.Add("0");
                        }

                        if (!listWaterTemperature.Contains("4"))
                        {
                            listWaterTemperature.Add("4");
                        }
                    }
                }

                if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                {
                    WaterLevelAndCurrentSpeed wc = sp1.Controls[i] as WaterLevelAndCurrentSpeed;
                    if (wc.cbbType.SelectedIndex == 0)
                    {
                        //if (!listDevice1.Contains("0"))
                        //{
                        //    listDevice1.Add("0");
                        //}

                        //if (!listDevice1.Contains("1"))
                        //{
                        //    listDevice1.Add("1");
                        //}
                        if (!listDevice1.Contains("01"))
                        {
                            listDevice1.Add("01");
                        }

                        if (!listWaterTemperature.Contains("3"))
                        {
                            listWaterTemperature.Add("3");
                        }
                    }

                    if (wc.cbbType.SelectedIndex == 1)
                    {
                        //if (!listDevice2.Contains("0"))
                        //{
                        //    listDevice2.Add("0");
                        //}

                        //if (!listDevice2.Contains("1"))
                        //{
                        //    listDevice2.Add("1");
                        //}
                        if (!listDevice2.Contains("01"))
                        {
                            listDevice2.Add("01");
                        }

                        if (!listWaterTemperature.Contains("4"))
                        {
                            listWaterTemperature.Add("4");
                        }
                    }
                }

                if (sp1.Controls[i] is GatePosition)
                {
                    GatePosition gp = sp1.Controls[i] as GatePosition;
                    if (gp.cbbType.SelectedIndex == 0)
                    {
                        if (!listDevice1.Contains("3"))
                        {
                            listDevice1.Add("3");
                        }
                    }

                    if (gp.cbbType.SelectedIndex == 1)
                    {
                        if (!listDevice2.Contains("3"))
                        {
                            listDevice2.Add("3");
                        }
                    }
                }

                if (sp1.Controls[i] is WaterQuality)
                {
                    WaterQuality wq = sp1.Controls[i] as WaterQuality;
                    int selectIndex = wq.intIndex;
                    //水质 在线PH传感器
                    if (selectIndex == 0)
                    {
                        listWaterTemperature.Add("5");
                    }

                    //水质 在线溶解氧传感器
                    if (selectIndex == 1)
                    {
                        listWaterTemperature.Add("6");
                    }

                    //水质 在线电导率传感器
                    if (selectIndex == 2)
                    {
                        listWaterTemperature.Add("7");
                    }

                    //水质 在线浊度传感器(1000NTU)
                    if (selectIndex == 3)
                    {
                        listWaterTemperature.Add("8");
                    }

                    //水质 在线浊度传感器(4000NTU)
                    if (selectIndex == 4)
                    {
                        listWaterTemperature.Add("9");
                    }

                    //水质 在线COD传感器
                    if (selectIndex == 5)
                    {
                        listWaterTemperature.Add("10");
                    }

                    //水质 在线氨氮传感器
                    if (selectIndex == 6)
                    {
                        listWaterTemperature.Add("11");
                    }

                    //水质 在线余氯传感器
                    if (selectIndex == 7)
                    {
                        listWaterTemperature.Add("12");
                    }

                    //水质 在线多参数水质传感器
                    if (selectIndex == 8 || selectIndex == 9 || selectIndex == 10)
                    {
                        listWaterTemperature.Add("13");
                    }

                    //水质 在线ORP传感器
                    if (selectIndex == 11)
                    {
                        listWaterTemperature.Add("14");
                    }
                }

                if (sp1.Controls[i] is WaterLevelAndCurrentSpeeds)//多流速
                {
                    if (!listDevice1.Contains("4"))
                    {
                        listDevice1.Add("4");
                    }
                }
            }
            BindFlowList1();
            BindFlowList2();
            BindWaterTemperature();
        }

        public void SetWaterLevelSetting()
        {
            btnWaterLevelSetting.Visible = false;
            if (cbbJs1.SelectedItem != null && cbbJs2.SelectedItem != null)
            {
                int intFs = (cbbJs1.SelectedItem as ListItem).Value;
                int intDm = cbbDm1.SelectedIndex;
                int intFs1 = (cbbJs2.SelectedItem as ListItem).Value;
                int intDm1 = cbbDm2.SelectedIndex;
                btnYc1.Visible = false;
                if (intFs == 0 || intFs1 == 0)
                {
                    if (intDm == 6 || intDm1 == 6)
                    {
                        btnWaterLevelSetting.Visible = true;
                    }

                    if (!btnYc1.Visible)
                    {
                        btnWaterLevelSetting.Location = btnYc1.Location;
                    }
                    else
                    {
                        btnWaterLevelSetting.Location = new Point(1021, 24);
                    }
                }
            }
        }

        /// <summary>
        /// 获取设备配置
        /// </summary>
        /// <returns>设备配置字节数组</returns>
        public byte[] GetConfig()
        {
            try
            {
                //基本配置
                rtuConfigInfo.StationType = Convert.ToByte(cbb1.SelectedIndex);
                rtuConfigInfo.StationNo = new byte[5];
                if (txtBox1.Text.Trim() != string.Empty && txtBox1.Text.Trim().Length == 10)
                {
                    rtuConfigInfo.StationNo = Protocol.ConvertHexStringToBytes(txtBox1.Text);
                }
                byte[] temp = new byte[62];
                byte[] bs = System.Text.Encoding.Default.GetBytes(txtBox2.Text.Trim());
                Array.Copy(bs, 0, temp, 0, bs.Length);
                rtuConfigInfo.StationName = temp;
                rtuConfigInfo.ReportingCycle = Convert.ToByte((cbbNud1.SelectedItem as ListItem).Value); 
                rtuConfigInfo.DataSaveCycel = Convert.ToByte((cbbNud2.SelectedItem as ListItem).Value);
                rtuConfigInfo.PreheatTime = Convert.ToByte(nud6.Value);
                rtuConfigInfo.HeartbeatCycel = Convert.ToByte(nud3.Value);
                rtuConfigInfo.WorkMode = Convert.ToByte(cbb2.SelectedIndex);
                rtuConfigInfo.TimingReport = Convert.ToByte(nud4.SelectedIndex);
                rtuConfigInfo.HourReport = Convert.ToByte(cbb3.SelectedIndex);
                rtuConfigInfo.AlarmCount = Convert.ToByte(nud5.SelectedIndex);
                rtuConfigInfo.AutoTiming = Convert.ToByte(cbb4.SelectedIndex);
                rtuConfigInfo.ModbusSlaveAddr = Convert.ToByte(nud7.Value);
                rtuConfigInfo.Function_485_3 = Convert.ToByte(cbb7.SelectedIndex);
                rtuConfigInfo.RainTimeReport = Convert.ToByte(cbb8.SelectedIndex);
                rtuConfigInfo.Volt_work_min = Convert.ToByte(Convert.ToDecimal(txtBox3.Text.Trim()) * 10);

                //以太网配置
                rtuConfigInfo.EthernetStatus = Convert.ToByte(0);
                if (cbb13.SelectedIndex == 1 || cbb23.SelectedIndex == 1 || cbb33.SelectedIndex == 1)
                {
                    rtuConfigInfo.EthernetStatus = Convert.ToByte(1);//Convert.ToByte(cbbYt1.SelectedIndex);
                }
                rtuConfigInfo.EthernetDHCP = Convert.ToByte(cbbYt2.SelectedIndex);

                string[] strValue1 = ipAddressInput1.Value.Trim().Split(new char[] { '.' });
                string[] strValue2 = ipAddressInput2.Value.Trim().Split(new char[] { '.' });
                string[] strValue3 = ipAddressInput3.Value.Trim().Split(new char[] { '.' });
                string[] strValue4 = ipAddressInput4.Value.Trim().Split(new char[] { '.' });
                string[] strValue5 = ipAddressInput5.Value.Trim().Split(new char[] { '.' });
                for (int i = 0; i < 4; i++) 
                {
                    rtuConfigInfo.EthernetIP[i] = Convert.ToByte(strValue1[i]);
                    rtuConfigInfo.EthernetGateway[i] = Convert.ToByte(strValue2[i]);
                    rtuConfigInfo.EthernetNetmask[i] = Convert.ToByte(strValue3[i]);
                    rtuConfigInfo.EthernetDNS[i] = Convert.ToByte(strValue4[i]);
                    rtuConfigInfo.EthernetBackupDNS[i] = Convert.ToByte(strValue5[i]);
                }
                rtuConfigInfo.EthernetResetTime = Convert.ToByte(nudYt1.Value);

                //中心站配置
                strValue1 = ip1.Value.Split(new char[] { '.' });
                strValue2 = ip2.Value.Split(new char[] { '.' });
                strValue3 = ip3.Value.Split(new char[] { '.' });
                strValue4 = ip4.Value.Split(new char[] { '.' });
                strValue5 = ip5.Value.Split(new char[] { '.' });
                for (int i = 0; i < strValue1.Length; i++)
                {
                    rtuConfigInfo.CentralStationIP1[i] = Convert.ToByte(strValue1[i]);
                    rtuConfigInfo.CentralStationIP2[i] = Convert.ToByte(strValue2[i]);
                    rtuConfigInfo.CentralStationIP3[i] = Convert.ToByte(strValue3[i]);
                    rtuConfigInfo.CentralStationIP4[i] = Convert.ToByte(strValue4[i]);
                    rtuConfigInfo.CentralStationIP5[i] = Convert.ToByte(strValue5[i]);
                }

                byte[] bytes = BitConverter.GetBytes((ushort)nud11.Value);
                rtuConfigInfo.CentralStationPort1[1] = bytes[0];
                rtuConfigInfo.CentralStationPort1[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud21.Value);
                rtuConfigInfo.CentralStationPort2[1] = bytes[0];
                rtuConfigInfo.CentralStationPort2[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud31.Value);
                rtuConfigInfo.CentralStationPort3[1] = bytes[0];
                rtuConfigInfo.CentralStationPort3[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud41.Value);
                rtuConfigInfo.CentralStationPort4[1] = bytes[0];
                rtuConfigInfo.CentralStationPort4[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud51.Value);
                rtuConfigInfo.CentralStationPort5[1] = bytes[0];
                rtuConfigInfo.CentralStationPort5[0] = bytes[1];

                bytes = BitConverter.GetBytes((ushort)nud12.Value);
                rtuConfigInfo.CentralStationBackupPort1[1] = bytes[0];
                rtuConfigInfo.CentralStationBackupPort1[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud22.Value);
                rtuConfigInfo.CentralStationBackupPort2[1] = bytes[0];
                rtuConfigInfo.CentralStationBackupPort2[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud32.Value);
                rtuConfigInfo.CentralStationBackupPort3[1] = bytes[0];
                rtuConfigInfo.CentralStationBackupPort3[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud42.Value);
                rtuConfigInfo.CentralStationBackupPort4[1] = bytes[0];
                rtuConfigInfo.CentralStationBackupPort4[0] = bytes[1];

                rtuConfigInfo.CentralStationAddr[0] = Convert.ToByte(nud14.Value);
                rtuConfigInfo.CentralStationAddr[1] = Convert.ToByte(nud24.Value);
                rtuConfigInfo.CentralStationAddr[2] = Convert.ToByte(nud34.Value);
                rtuConfigInfo.CentralStationAddr[3] = Convert.ToByte(nud44.Value);

                bytes = BitConverter.GetBytes((ushort)nud15.Value);
                rtuConfigInfo.CentralStationPassward1[1] = bytes[0];
                rtuConfigInfo.CentralStationPassward1[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud25.Value);
                rtuConfigInfo.CentralStationPassward2[1] = bytes[0];
                rtuConfigInfo.CentralStationPassward2[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud35.Value);
                rtuConfigInfo.CentralStationPassward3[1] = bytes[0];
                rtuConfigInfo.CentralStationPassward3[0] = bytes[1];
                bytes = BitConverter.GetBytes((ushort)nud45.Value);
                rtuConfigInfo.CentralStationPassward4[1] = bytes[0];
                rtuConfigInfo.CentralStationPassward4[0] = bytes[1];

                rtuConfigInfo.CentralStationPhone1 = txtNo1.Text.PadRight(13, '\0').ToCharArray();
                rtuConfigInfo.CentralStationPhone2 = txtNo2.Text.PadRight(13, '\0').ToCharArray();
                rtuConfigInfo.CentralStationPhone3 = txtNo3.Text.PadRight(13, '\0').ToCharArray();

                rtuConfigInfo.CentralStationTransportProtocol[0] = Convert.ToByte(cbb11.SelectedIndex);
                rtuConfigInfo.CentralStationTransportProtocol[1] = Convert.ToByte(cbb21.SelectedIndex);
                rtuConfigInfo.CentralStationTransportProtocol[2] = Convert.ToByte(cbb31.SelectedIndex);

                rtuConfigInfo.CentralStationReportProtocol[0] = Convert.ToByte(cbb12.SelectedIndex);
                rtuConfigInfo.CentralStationReportProtocol[1] = Convert.ToByte(cbb22.SelectedIndex);
                rtuConfigInfo.CentralStationReportProtocol[2] = Convert.ToByte(cbb32.SelectedIndex);

                rtuConfigInfo.CentralStationHardwareInterface[0] = Convert.ToByte(cbb13.SelectedIndex);
                rtuConfigInfo.CentralStationHardwareInterface[1] = Convert.ToByte(cbb23.SelectedIndex);
                rtuConfigInfo.CentralStationHardwareInterface[2] = Convert.ToByte(cbb33.SelectedIndex);

                rtuConfigInfo.CentralStationVpnEnable = Convert.ToByte(cbb5.SelectedIndex);

                //if (txtBox51.Text != string.Empty)
                //{
                    rtuConfigInfo.CentralStationVpnPoint = txtBox51.Text.PadRight(16, '\0').ToCharArray();
                //}

                //if (txtBox52.Text != string.Empty)
                //{
                    rtuConfigInfo.CentralStationVpnName = txtBox52.Text.PadRight(16, '\0').ToCharArray();
                //}

                //if (txtBox53.Text != string.Empty)
                //{
                    rtuConfigInfo.CentralStationVpnPassword = txtBox53.Text.PadRight(16, '\0').ToCharArray();
                //}

                rtuConfigInfo.CentralStationRemoteVpnEnable = Convert.ToByte(cbb6.SelectedIndex);
                rtuConfigInfo.WaterLevel_Enable = 0;
                rtuConfigInfo.CurrentSpeed_Enable = 0;
                rtuConfigInfo.WaterFlow_Enable = 0;
                rtuConfigInfo.GatePosition_Enable = 0;
                rtuConfigInfo.RainFall_Enable = 0;
                rtuConfigInfo.WaterQuality_Enable[0] = 0;
                rtuConfigInfo.WaterQuality_Enable[1] = 0;
                rtuConfigInfo.Camera_Enable = 0;
                rtuConfigInfo.Video_Enable = 0;
                rtuConfigInfo.WaterFlowCount_Enable = 0;
                rtuConfigInfo.WaterTemperature_Enable = 0;
                rtuConfigInfo.MultiSpeed_Enable = 0;
                rtuConfigInfo.SoilTempHumi_Enable = 0;
                rtuConfigInfo.OsmoticPressure_Enable = 0;
                rtuConfigInfo.WindSpeed_Enable = 0;
                rtuConfigInfo.WindDir_Enable = 0;
                rtuConfigInfo.Atmosphere_Enable = 0;
                rtuConfigInfo.PmGas_Enable = 0;
                rtuConfigInfo.Pm25_Enable = 0;
                rtuConfigInfo.Pm10_Enable = 0;

                //4-20mA设置
                rtuConfigInfo.IoutputModule_Enable = Convert.ToByte(c1.SelectedIndex);
                rtuConfigInfo.IoutputModule_Addr = Convert.ToByte(c2.Value);
                rtuConfigInfo.IoutputModule_DeviceSelect = Convert.ToByte(c3.SelectedIndex);
                rtuConfigInfo.IoutputModule_DataSelect[0] = Convert.ToByte(c11.SelectedIndex);
                rtuConfigInfo.IoutputModule_4mAValue1 = BitConverter.GetBytes(Convert.ToUInt32(c12.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_20mAValue1 = BitConverter.GetBytes(Convert.ToUInt32(c13.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_DataSelect[1] = Convert.ToByte(c21.SelectedIndex);
                rtuConfigInfo.IoutputModule_4mAValue2 = BitConverter.GetBytes(Convert.ToUInt32(c22.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_20mAValue2 = BitConverter.GetBytes(Convert.ToUInt32(c23.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_DataSelect[2] = Convert.ToByte(c31.SelectedIndex);
                rtuConfigInfo.IoutputModule_4mAValue3 = BitConverter.GetBytes(Convert.ToUInt32(c32.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_20mAValue3 = BitConverter.GetBytes(Convert.ToUInt32(c33.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_DataSelect[3] = Convert.ToByte(c41.SelectedIndex);
                rtuConfigInfo.IoutputModule_4mAValue4 = BitConverter.GetBytes(Convert.ToUInt32(c42.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.IoutputModule_20mAValue4 = BitConverter.GetBytes(Convert.ToUInt32(c43.Value * 1000)).Reverse<byte>().ToArray();

                rtuConfigInfo.Iinput_Enable = Convert.ToByte(d1.SelectedIndex);
                rtuConfigInfo.Iin_DataSelect[0] = Convert.ToByte(d11.SelectedIndex);
                rtuConfigInfo.Iin_4mAValue1 = BitConverter.GetBytes(Convert.ToUInt32(d12.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.Iin_20mAValue1 = BitConverter.GetBytes(Convert.ToUInt32(d13.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.Iin_DataSelect[1] = Convert.ToByte(d21.SelectedIndex);
                rtuConfigInfo.Iin_4mAValue2 = BitConverter.GetBytes(Convert.ToUInt32(d22.Value * 1000)).Reverse<byte>().ToArray();
                rtuConfigInfo.Iin_20mAValue2 = BitConverter.GetBytes(Convert.ToUInt32(d23.Value * 1000)).Reverse<byte>().ToArray();

                if (chkJs1.Checked)
                {
                    rtuConfigInfo.WaterFlowCount_Enable |= 0x0001 << 0;
                    if (cbbJs1.SelectedItem != null)
                    {
                        rtuConfigInfo.WaterFlowCountSelect[0] = Convert.ToByte((cbbJs1.SelectedItem as ListItem).Value);
                    }

                    if (cbbDm1.SelectedItem != null)
                    {
                        rtuConfigInfo.WaterFlowSectionSelect[0] = Convert.ToByte(cbbDm1.SelectedIndex);
                    }
                }

                if (chkJs2.Checked)
                {
                    rtuConfigInfo.WaterFlowCount_Enable |= 0x0001 << 1;
                    if (cbbJs2.SelectedItem != null)
                    {
                        rtuConfigInfo.WaterFlowCountSelect[1] = Convert.ToByte((cbbJs2.SelectedItem as ListItem).Value);
                    }

                    if (cbbDm2.SelectedItem != null)
                    {
                        rtuConfigInfo.WaterFlowSectionSelect[1] = Convert.ToByte(cbbDm2.SelectedIndex);
                    }
                }

                for (int i = 0; i < sp1.Controls.Count; i++)
                {
                    if (sp1.Controls[i] is WaterLevel)
                    {
                        WaterLevel wl = sp1.Controls[i] as WaterLevel;
                        wl.GetValue();
                    }

                    if (sp1.Controls[i] is CurrentSpeed)
                    {
                        CurrentSpeed cs = sp1.Controls[i] as CurrentSpeed;
                        cs.GetValue();
                    }

                    if (sp1.Controls[i] is Flowmeters)
                    {
                        Flowmeters ft = sp1.Controls[i] as Flowmeters;
                        ft.GetValue();
                    }

                    if (sp1.Controls[i] is Flowmeters1)
                    {
                        Flowmeters1 ft1 = sp1.Controls[i] as Flowmeters1;
                        ft1.GetValue();
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                    {
                        WaterLevelAndCurrentSpeed wc = sp1.Controls[i] as WaterLevelAndCurrentSpeed;
                        wc.GetValue();
                    }

                    if (sp1.Controls[i] is GatePosition)
                    {
                        GatePosition gp = sp1.Controls[i] as GatePosition;
                        gp.GetValue();
                    }

                    if (sp1.Controls[i] is RainFall)
                    {
                        RainFall rf = sp1.Controls[i] as RainFall;
                        rf.GetValue();
                    }

                    if (sp1.Controls[i] is WaterQuality)
                    {
                        WaterQuality wq = sp1.Controls[i] as WaterQuality;
                        wq.GetValue();
                    }

                    if (sp1.Controls[i] is Camera)
                    {
                        Camera ca = sp1.Controls[i] as Camera;
                        ca.GetValue();
                    }

                    if (sp1.Controls[i] is Video)
                    {
                        Video vi = sp1.Controls[i] as Video;
                        vi.GetValue();
                    }

                    if (sp1.Controls[i] is WaterTemperature)
                    {
                        WaterTemperature w = sp1.Controls[i] as WaterTemperature;
                        w.GetValue();
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeeds)
                    {
                        WaterLevelAndCurrentSpeeds wc = sp1.Controls[i] as WaterLevelAndCurrentSpeeds;
                        wc.GetValue();
                    }

                    if (sp1.Controls[i] is Soil)
                    {
                        Soil s = sp1.Controls[i] as Soil;
                        s.GetValue();
                    }

                    if (sp1.Controls[i] is OsmoticPressure)
                    {
                        OsmoticPressure s = sp1.Controls[i] as OsmoticPressure;
                        s.GetValue();
                    }

                    if (sp1.Controls[i] is WindSpeed)
                    {
                        WindSpeed s = sp1.Controls[i] as WindSpeed;
                        s.GetValue();
                    }

                    if (sp1.Controls[i] is WindDir)
                    {
                        WindDir s = sp1.Controls[i] as WindDir;
                        s.GetValue();
                    }
                    if (sp1.Controls[i] is Atmosphere)
                    {
                        Atmosphere s = sp1.Controls[i] as Atmosphere;
                        s.GetValue();
                    }
                    if (sp1.Controls[i] is MeteorologicalStationSeven)
                    {
                        MeteorologicalStationSeven s = sp1.Controls[i] as MeteorologicalStationSeven;
                        s.GetValue();
                    }
                    if (sp1.Controls[i] is PmGas)
                    {
                        PmGas s = sp1.Controls[i] as PmGas;
                        s.GetValue();
                    }
                    if (sp1.Controls[i] is Pm25)
                    {
                        Pm25 s = sp1.Controls[i] as Pm25;
                        s.GetValue();
                    }
                    if (sp1.Controls[i] is Pm10)
                    {
                        Pm10 s = sp1.Controls[i] as Pm10;
                        s.GetValue();
                    }
                }
                return Protocol.StructToBytes(rtuConfigInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 检查设备配置
        /// </summary>
        /// <returns>true,false</returns>
        public bool CheckConfig()
        {
            try
            {
                //基本配置
                if (txtBox1.Text.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("请输入遥测站编号！");
                    return false;
                }

                if (txtBox1.Text.Trim().Length != 10)
                {
                    Common.ShowErrorMessage("遥测站编号必须为10位数字！");
                    return false;
                }

                if (txtBox2.Text.Trim() != string.Empty)
                {
                    char[] c = txtBox2.Text.Trim().ToCharArray();
                    if (c.Length > 62)
                    {
                        Common.ShowErrorMessage("请检查遥测站名称长度，最多31个汉字或62个字母!");
                        return false;
                    }
                }
                if (int.Parse(txtBox3.Text.Trim()) > 24)
                {
                    Common.ShowErrorMessage("最小工作电压不能超过24V!");
                    return false;
                }
                int nud1 = (cbbNud1.SelectedItem as ListItem).Value;
                int nud2 = (cbbNud2.SelectedItem as ListItem).Value;
                if (nud2 > nud1)
                {
                    Common.ShowErrorMessage("采集周期必须小于等于加报周期！");
                    return false;
                }

                if (nud2 * 60 <= nud6.Value)
                {
                    Common.ShowErrorMessage("采集周期必须大于预热时间！");
                    return false;
                }

                if (cbb2.SelectedIndex == 0 && nud6.Value == 0)
                {
                    Common.ShowErrorMessage("预热时间填写0时，工作模式必须选择常在线模式！");
                    return false;
                }

                // 4为RS485通道3透传
                if (cbb2.SelectedIndex == 0 && (cbb7.SelectedIndex != 0 && cbb7.SelectedIndex != 4))
                {
                    Common.ShowErrorMessage("RS485-3端口功能选择迪文屏功能、modbus从机、LED点阵屏，工作模式必须选择常在线模式！");
                    return false;
                }

                //中心站配置
                if (ip1.Value.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("中心站1IP地址不能为空！");
                    return false;
                }

                if (ip2.Value.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("中心站2IP地址不能为空！");
                    return false;
                }

                if (ip3.Value.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("中心站3IP地址不能为空！");
                    return false;
                }

                if (ip4.Value.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("中心站4IP地址不能为空！");
                    return false;
                }

                if (ip5.Value.Trim() == string.Empty)
                {
                    Common.ShowErrorMessage("远程后台服务器设置IP地址不能为空！");
                    return false;
                }

                //if (txtNo1.Text.Replace("\0", "") != string.Empty)
                //{
                //    if (txtNo1.Text.Length != 13)
                //    {
                //        Common.ShowErrorMessage("中心站1电话号码长度必须为13位！");
                //        return false;
                //    }
                //    else
                //    {
                //        if (txtNo1.Text[0] != '8' || txtNo1.Text[1] != '6' || txtNo1.Text[2] != '1')
                //        {
                //            Common.ShowErrorMessage("中心站1电话号码必须为861开头！");
                //            return false;
                //        }
                //    }
                //}

                //if (txtNo2.Text.Replace("\0", "") != string.Empty)
                //{
                //    if (txtNo2.Text.Length != 13)
                //    {
                //        Common.ShowErrorMessage("中心站2电话号码长度必须为13位！");
                //        return false;
                //    }
                //    else
                //    {
                //        if (txtNo2.Text[0] != '8' || txtNo2.Text[1] != '6' || txtNo2.Text[2] != '1')
                //        {
                //            Common.ShowErrorMessage("中心站2电话号码必须为861开头！");
                //            return false;
                //        }
                //    }
                //}

                //if (txtNo3.Text.Replace("\0", "") != string.Empty)
                //{
                //    if (txtNo3.Text.Length != 13)
                //    {
                //        Common.ShowErrorMessage("中心站3电话号码长度必须为13位！");
                //        return false;
                //    }
                //    else
                //    {
                //        if (txtNo3.Text[0] != '8' || txtNo3.Text[1] != '6' || txtNo3.Text[2] != '1')
                //        {
                //            Common.ShowErrorMessage("中心站3电话号码必须为861开头！");
                //            return false;
                //        }
                //    }
                //}

                //报文协议Http Post
                if (cbb12.SelectedIndex == 1 && cbb11.SelectedIndex != 0)
                {
                    Common.ShowErrorMessage("中心站1报文协议选择Http Post，中心站1传输协议必须为TCP协议！");
                    return false;
                }

                if (cbb22.SelectedIndex == 1 && cbb21.SelectedIndex != 0)
                {
                    Common.ShowErrorMessage("中心站2报文协议选择Http Post，中心站2传输协议必须为TCP协议！");
                    return false;
                }

                if (cbb32.SelectedIndex == 1 && cbb31.SelectedIndex != 0)
                {
                    Common.ShowErrorMessage("中心站3报文协议选择Http Post，中心站3传输协议必须为TCP协议！");
                    return false;
                }

                //以太网
                if (cbb13.SelectedIndex == 1 || cbb23.SelectedIndex == 1 || cbb33.SelectedIndex == 1)
                {
                    //if (cbbYt1.SelectedIndex == 0)
                    //{
                    //    Common.ShowErrorMessage("中心站硬件接口选择有线以太网，以太外网开关必须选择开启状态！");
                    //    return false;
                    //}

                    //自动DHCP关闭
                    if (cbbYt2.SelectedIndex == 0)
                    {
                        if (ipAddressInput1.Value.Trim() == string.Empty)
                        {
                            Common.ShowErrorMessage("请输入IP地址！");
                            return false;
                        }

                        if (ipAddressInput2.Value.Trim() == string.Empty)
                        {
                            Common.ShowErrorMessage("请输入网关！");
                            return false;
                        }

                        if (ipAddressInput3.Value.Trim() == string.Empty)
                        {
                            Common.ShowErrorMessage("请输入子网掩码！");
                            return false;
                        }

                        if (ipAddressInput4.Value.Trim() == string.Empty)
                        {
                            Common.ShowErrorMessage("请输入主DNS！");
                            return false;
                        }

                        if (ipAddressInput5.Value.Trim() == string.Empty)
                        {
                            Common.ShowErrorMessage("请输入备用DNS！");
                            return false;
                        }
                    }

                    if (cbb2.SelectedIndex == 0)
                    {
                        Common.ShowErrorMessage("中心站硬件接口选择有线以太网，工作模式必须选择常在线模式！");
                        return false;
                    }
                }

                if (txtBox51.Text.Replace("\0", "") != string.Empty)
                {
                    for (int i = 0; i < txtBox51.Text.Replace("\0", "").Length; i++)
                    {
                        if (txtBox51.Text[i] < ' ' || txtBox51.Text[i] > '~')
                        {
                            Common.ShowErrorMessage("接入点必须为ASCII字符！");
                            return false;
                        }
                    }
                }

                if (txtBox52.Text.Replace("\0", "") != string.Empty)
                {
                    for (int i = 0; i < txtBox52.Text.Replace("\0", "").Length; i++)
                    {
                        if (txtBox52.Text[i] < ' ' || txtBox52.Text[i] > '~')
                        {
                            Common.ShowErrorMessage("用户名必须为ASCII字符！");
                            return false;
                        }
                    }
                }

                if (txtBox53.Text.Replace("\0", "") != string.Empty)
                {
                    for (int i = 0; i < txtBox53.Text.Replace("\0", "").Length; i++)
                    {
                        if (txtBox53.Text[i] < ' ' || txtBox53.Text[i] > '~')
                        {
                            Common.ShowErrorMessage("密码必须为ASCII字符！");
                            return false;
                        }
                    }
                }

                //设备配置
                ArrayList listIndex = new ArrayList();
                ArrayList listAddr = new ArrayList();
                ArrayList listAddr1 = new ArrayList();
                ArrayList listZh = new ArrayList();
                for (int i = 0; i < sp1.Controls.Count; i++)
                {
                    if (sp1.Controls[i] is WaterLevel)
                    {
                        WaterLevel wl = sp1.Controls[i] as WaterLevel;
                        string strID = wl.Tag.ToString() + wl.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("水位计不能同时添加两个相同的水位计1或水位计2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (wl.DeviceSelectNo == 7 || wl.DeviceSelectNo == 8)//4-20mA输入开关检查
                        {
                            if (d1.SelectedIndex == 0)
                            {
                                Common.ShowErrorMessage("请开启外置4-20mA输入模块开关！");
                                return false;
                            }
                        }
                        else
                        {
                            if (!listAddr.Contains(wl.nud2.Value))
                            {
                                listAddr.Add(wl.nud2.Value);
                            }
                            else
                            {
                                Common.ShowErrorMessage("设备通讯地址重复！");
                                return false;
                            }
                        }
                    }

                    if (sp1.Controls[i] is CurrentSpeed)
                    {
                        CurrentSpeed cs = sp1.Controls[i] as CurrentSpeed;
                        string strID = cs.Tag.ToString() + cs.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("流速仪不能同时添加两个相同的流速仪1或流速仪2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!listAddr.Contains(cs.nud1.Value))
                        {
                            listAddr.Add(cs.nud1.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is Flowmeters)
                    {
                        Flowmeters ft = sp1.Controls[i] as Flowmeters;
                        string strID = ft.Tag.ToString() + ft.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("流量计不能同时添加两个相同的流量计1或流量计2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!listAddr.Contains(ft.nud2.Value))
                        {
                            listAddr.Add(ft.nud2.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }

                        if (ft.DeviceSelectNo == 0 || ft.DeviceSelectNo == 5)//多普勒超声流量计(DX-LSX-1)或多普勒超声流量计(ADV11EAA)
                        {
                            if (!CheckWaterLevelAndCurrentSpeed(ft.cbbType.SelectedIndex, ft.DeviceSelectNo))
                            {
                                return false;
                            }
                        }

                        if (ft.DeviceSelectNo == 4)//超声波流量计(TUF-2000-S)
                        {
                            if (ft.cbbType.SelectedIndex == 0 && chkJs1.Checked == false)
                            {
                                Common.ShowErrorMessage("请勾选流量1积算功能！");
                                return false;
                            }

                            if (ft.cbbType.SelectedIndex == 1 && chkJs2.Checked == false)
                            {
                                Common.ShowErrorMessage("请勾选流量2积算功能！");
                                return false;
                            }
                        }
                    }

                    if (sp1.Controls[i] is Flowmeters1)
                    {
                        Flowmeters1 ft1 = sp1.Controls[i] as Flowmeters1;
                        string strID = ft1.Tag.ToString() + ft1.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("流量计不能同时添加两个相同的流量计1或流量计2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!listAddr.Contains(ft1.nud2.Value))
                        {
                            listAddr.Add(ft1.nud2.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }

                        if (ft1.cbbType.SelectedIndex == 0)
                        {
                            if (listIndex.Contains("00") && listIndex.Contains("20"))
                            {
                                Common.ShowErrorMessage("明渠流量计已使用水位计1，请删除水位计1！");
                                return false;
                            }
                        }

                        if (ft1.cbbType.SelectedIndex == 1)
                        {
                            if (listIndex.Contains("01") && listIndex.Contains("21"))
                            {
                                Common.ShowErrorMessage("明渠流量计已使用水位计2，请删除水位计2！");
                                return false;
                            }
                        }
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeed)
                    {
                        WaterLevelAndCurrentSpeed wc = sp1.Controls[i] as WaterLevelAndCurrentSpeed;
                        string strID = wc.Tag.ToString() + wc.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("流量计不能同时添加两个相同的流量计1或流量计2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!CheckWaterLevelAndCurrentSpeed(wc.cbbType.SelectedIndex, wc.DeviceSelectNo))
                        {
                            return false;
                        }

                        if (!listAddr.Contains(wc.nud2.Value))
                        {
                            listAddr.Add(wc.nud2.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }

                        if (!listAddr.Contains(wc.nud11.Value))
                        {
                            listAddr.Add(wc.nud11.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is GatePosition)
                    {
                        GatePosition gp = sp1.Controls[i] as GatePosition;
                        string strID = gp.Tag.ToString() + gp.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("闸位计不能同时添加两个相同的闸位计1或闸位计2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!listAddr.Contains(gp.nud1.Value))
                        {
                            listAddr.Add(gp.nud1.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }

                        //if (!CheckWaterLevel(gp.cbbType.SelectedIndex))
                        //{
                        //    Common.ShowErrorMessage(string.Format("闸位计{0}需配合水位计{0}使用，请添加水位计{0}！", gp.cbbType.SelectedIndex + 1));
                        //    return false;
                        //}
                    }

                    if (sp1.Controls[i] is WaterQuality)
                    {
                        WaterQuality wq = sp1.Controls[i] as WaterQuality;
                        wq.GetValue();
                        if (!listAddr.Contains(wq.nudAddr.Value))
                        {
                            listAddr.Add(wq.nudAddr.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is Camera)
                    {
                        Camera ca = sp1.Controls[i] as Camera;
                        string strID = ca.Tag.ToString() + ca.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("相机不能同时添加两个相同的相机1或相机2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }

                        if (!listAddr1.Contains(ca.nud1.Value))
                        {
                            listAddr1.Add(ca.nud1.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("相机通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is Video)
                    {
                        Video vi = sp1.Controls[i] as Video;
                        string strID = vi.Tag.ToString() + vi.cbbType.SelectedIndex;
                        if (listIndex.Contains(strID))
                        {
                            Common.ShowErrorMessage("摄像头不能同时添加两个相同的摄像头1或摄像头2！");
                            return false;
                        }
                        else
                        {
                            listIndex.Add(strID);
                        }
                    }

                    if (sp1.Controls[i] is WaterTemperature)
                    {
                        WaterTemperature w = sp1.Controls[i] as WaterTemperature;
                        w.GetValue();
                        if (!listAddr.Contains(w.nud1.Value))
                        {
                            listAddr.Add(w.nud1.Value);
                        }
                        else
                        {
                            if (w.ccbZz.SelectedIndex == 0)
                            {
                                Common.ShowErrorMessage("设备通讯地址重复！");
                                return false;
                            }
                        }
                    }

                    if (sp1.Controls[i] is WaterLevelAndCurrentSpeeds)
                    {
                        WaterLevelAndCurrentSpeeds wc = sp1.Controls[i] as WaterLevelAndCurrentSpeeds;
                        if (!wc.CheckConfig())
                        {
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is Soil)
                    {
                        Soil s = sp1.Controls[i] as Soil;
                        s.GetValue();
                        if (!listAddr.Contains(s.nudAddr.Value))
                        {
                            listAddr.Add(s.nudAddr.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is OsmoticPressure)
                    {
                        OsmoticPressure s = sp1.Controls[i] as OsmoticPressure;
                        s.GetValue();
                        if (!listAddr.Contains(s.nudAddr.Value))
                        {
                            listAddr.Add(s.nudAddr.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is WindSpeed)
                    {
                        WindSpeed s = sp1.Controls[i] as WindSpeed;
                        s.GetValue();
                        if (!listAddr.Contains(s.nudAddr.Value))
                        {
                            listAddr.Add(s.nudAddr.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }

                    if (sp1.Controls[i] is WindDir)
                    {
                        WindDir s = sp1.Controls[i] as WindDir;
                        s.GetValue();
                        if (!listAddr.Contains(s.nudAddr.Value))
                        {
                            listAddr.Add(s.nudAddr.Value);
                        }
                        else
                        {
                            Common.ShowErrorMessage("设备通讯地址重复！");
                            return false;
                        }
                    }
                }

                if (c1.SelectedIndex == 1)
                {
                    if (!listAddr.Contains(c2.Value))
                    {
                        listAddr.Add(c2.Value);
                    }
                    else
                    {
                        Common.ShowErrorMessage("外置4-20mA输出模块地址重复！");
                        return false;
                    }
                }

                //if (!(listIndex.Contains("00") && listIndex.Contains("01")))
                //{
                //    if (listZh.Count == 1)
                //    {
                //        if (listIndex.Contains("00") && listZh.Contains("20"))
                //        {
                //            Common.ShowErrorMessage("多普勒超声流量计设备标识不能与水位计的设备标识相同！");
                //            return false;
                //        }

                //        if (listIndex.Contains("01") && listZh.Contains("21"))
                //        {
                //            Common.ShowErrorMessage("多普勒超声流量计设备标识不能与水位计的设备标识相同！");
                //            return false;
                //        }
                //    }
                //}

                if (chkJs1.Checked)
                {
                    if (cbbJs1.SelectedItem == null || cbbDm1.SelectedItem == null)
                    {
                        Common.ShowErrorMessage("打开流量1积算功能，必须选择流量计算来源和流量槽断面！");
                        return false;
                    }
                }

                if (chkJs2.Checked)
                {
                    if (cbbJs2.SelectedItem == null || cbbDm2.SelectedItem == null)
                    {
                        Common.ShowErrorMessage("打开流量2积算功能，必须选择流量计算来源和流量槽断面！");
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 初始流量积算来源
        /// </summary>
        /// <param name="selectIndex">设备标识</param>
        /// <param name="type">设备类型</param>
        /// <param name="tabIndex">设备序号</param>
        public void InitFlowmetersSource(int selectIndex, int type, int tabIndex)
        {
            int intWt = 0;
            int index = IsContains(type, tabIndex);
            if (selectIndex == 0)
            {
                if (!listDevice1.Contains(type.ToString()))
                {
                    listDevice1.Add(type.ToString());
                    BindFlowList1();
                }

                if (index != 1)
                {
                    listDevice2.Remove(type.ToString());
                    BindFlowList2();
                }
            }

            if (selectIndex == 1)
            {
                if (!listDevice2.Contains(type.ToString()))
                {
                    listDevice2.Add(type.ToString());
                    BindFlowList2();
                }

                if (index == 1)
                {
                    listDevice1.Remove(type.ToString());
                    BindFlowList1();
                }
            }

            if (type == 0)
            {
                if (selectIndex == 0)
                {
                    intWt = 1;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("2");
                        BindWaterTemperature();
                    }
                }

                if (selectIndex == 1)
                {
                    intWt = 2;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("1");
                        BindWaterTemperature();
                    }
                }

                if (!listWaterTemperature.Contains(intWt.ToString()))
                {
                    listWaterTemperature.Add(intWt.ToString());
                    BindWaterTemperature();
                }
            }

            if (type == 2)
            {
                if (selectIndex == 0)
                {
                    intWt = 3;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("4");
                        BindWaterTemperature();
                    }
                }

                if (selectIndex == 1)
                {
                    intWt = 4;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("3");
                        BindWaterTemperature();
                    }
                }


                if (!listWaterTemperature.Contains(intWt.ToString()))
                {
                    listWaterTemperature.Add(intWt.ToString());
                    BindWaterTemperature();
                }
            }
        }

        /// <summary>
        /// 初始流量积算来源
        /// </summary>
        /// <param name="selectIndex">设备标识</param>
        /// <param name="type">设备类型</param>
        /// <param name="tabIndex">设备序号</param>
        public void InitFlowmetersSource1(int selectIndex, int type, int tabIndex, int type1)
        {
            int intWt = 0;
            int index = IsContains(type1, tabIndex);
            if (selectIndex == 0)
            {
                if (!listDevice1.Contains(type.ToString()))
                {
                    listDevice1.Add(type.ToString());
                    BindFlowList1();
                }

                if (index != 1)
                {
                    listDevice2.Remove(type.ToString());
                    BindFlowList2();
                }
            }

            if (selectIndex == 1)
            {
                if (!listDevice2.Contains(type.ToString()))
                {
                    listDevice2.Add(type.ToString());
                    BindFlowList2();
                }

                if (index == 1)
                {
                    listDevice1.Remove(type.ToString());
                    BindFlowList1();
                }
            }

            if (type == 0)
            {
                if (selectIndex == 0)
                {
                    intWt = 1;
                }

                if (selectIndex == 1)
                {
                    intWt = 2;
                }

                if (!listWaterTemperature.Contains(intWt.ToString()))
                {
                    listWaterTemperature.Add(intWt.ToString());
                    BindWaterTemperature();
                }
            }

            if (type == 2)
            {
                if (selectIndex == 0)
                {
                    intWt = 3;
                }

                if (selectIndex == 1)
                {
                    intWt = 4;
                }

                if (!listWaterTemperature.Contains(intWt.ToString()))
                {
                    listWaterTemperature.Add(intWt.ToString());
                    BindWaterTemperature();
                }
            }
        }

        /// <summary>
        /// 初始流量积算来源
        /// </summary>
        /// <param name="selectIndex">设备标识</param>
        /// <param name="type">设备类型</param>
        /// <param name="tabIndex">设备序号</param>
        public void InitFlowmetersSource2(int selectIndex, int type, int tabIndex)
        {
            int intWt = 0;
            int index = IsContains(type, tabIndex);
            if (selectIndex == 0)
            {
                if (!listDevice1.Contains("0"))
                {
                    listDevice1.Add("0");
                    BindFlowList1();
                }

                if (!listDevice1.Contains("1"))
                {
                    listDevice1.Add("1");
                    BindFlowList1();
                }

                if (index != 1)
                {
                    listDevice2.Remove("0");
                    listDevice2.Remove("1");
                    BindFlowList2();
                }
            }

            if (selectIndex == 1)
            {
                if (!listDevice2.Contains("0"))
                {
                    listDevice2.Add("0");
                    BindFlowList2();
                }

                if (!listDevice2.Contains("1"))
                {
                    listDevice2.Add("1");
                    BindFlowList2();
                }

                if (index == 1)
                {
                    listDevice1.Remove("0");
                    listDevice1.Remove("1");
                    BindFlowList1();
                }
            }

            if (type == 2)
            {
                if (selectIndex == 0)
                {
                    intWt = 3;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("4");
                        BindWaterTemperature();
                    }
                }

                if (selectIndex == 1)
                {
                    intWt = 4;
                    if (index == selectIndex)
                    {
                        listWaterTemperature.Remove("3");
                        BindWaterTemperature();
                    }
                }

                if (!listWaterTemperature.Contains(intWt.ToString()))
                {
                    listWaterTemperature.Add(intWt.ToString());
                    BindWaterTemperature();
                }
            }
        }

        /// <summary>
        /// 初始断面选择
        /// </summary>
        /// <param name="cb1">流量计算方式</param>
        /// <param name="cb2">断面选择</param>
        private void InitDm(ComboBoxEdit cb1, ComboBoxEdit cb2)
        {
            int intValue = cb1.SelectedItem != null ? (cb1.SelectedItem as ListItem).Value : -1;

            if (intValue == 0)//水位
            {
                cb2.Properties.Items.Clear();
                cb2.Properties.Items.AddRange(Common.JmList1);
            }

            if (intValue == 1)//水位+流速
            {
                cb2.Properties.Items.Clear();
                cb2.Properties.Items.AddRange(Common.JmList2);
            }

            if (intValue == 2)//水位+闸位
            {
                cb2.Properties.Items.Clear();
                cb2.Properties.Items.AddRange(Common.JmList3);
            }

            //if (intValue == 4)//流量计
            //{
            //    cb2.Properties.Items.Clear();
            //    cb2.Properties.Items.AddRange(Common.JmList4);
            //}

            if (intValue == 3)//超声波流量计 
            {
                cb2.Properties.Items.Clear();
                cb2.Properties.Items.AddRange(Common.JmList5);
            }

            if (intValue == 4)//水位+多流速
            {
                cb2.Properties.Items.Clear();
                cb2.Properties.Items.AddRange(Common.JmList6);
            }

            if (cb2.Properties.Items.Count > 0)
            {
                cb2.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 设备排序
        /// </summary>
        private void ControlsSort()
        {
            ArrayList ctrls = new ArrayList(sp1.Controls);
            for (int i = 0; i < ctrls.Count - 1; i++)
            {
                for (int j = 0; j < ctrls.Count - 1 - i; j++)
                {
                    Control c1 = ctrls[j] as Control;
                    Control c2 = ctrls[j + 1] as Control;
                    if (c1.TabIndex > c2.TabIndex)
                    {
                        Control temp = c1;
                        ctrls[j] = ctrls[j + 1];
                        ctrls[j + 1] = temp;
                    }
                }
            }

            sp1.Controls.Clear();
            for (int m = 0; m < ctrls.Count; m++)
            {
                sp1.Controls.Add(ctrls[m] as Control);
            }
        }

        /// <summary>
        /// 显示隐藏以太网设置
        /// </summary>
        private void ShowEthernet()
        {
            if (cbb13.SelectedIndex == 1 || cbb23.SelectedIndex == 1 || cbb33.SelectedIndex == 1)
            {
                groupControl1.Visible = true;
            }
            else
            {
                groupControl1.Visible = false;
            }
        }
        
        /// <summary>
        /// 添加设备
        /// </summary>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbbType.SelectedIndex != -1 && cbbDevice.SelectedIndex != -1)
                {
                    int intType = cbbType.SelectedIndex;
                    if (intType == 5)//水质
                    {
                        intType = Convert.ToInt16(cbbType.SelectedIndex.ToString() + cbbDevice.SelectedIndex.ToString());
                        if (cbbDevice.SelectedIndex == 3 || cbbDevice.SelectedIndex == 4)
                        {
                            intType = 53;
                        }

                        if (cbbDevice.SelectedIndex == 8 || cbbDevice.SelectedIndex == 9 || cbbDevice.SelectedIndex == 10)
                        {
                            intType = 58;
                        }
                    }
                    if (intType == 15)
                    {
                        //if (cbbDevice.SelectedIndex == 1 && flag2 == 0)
                        //{
                        //    intType = 151;
                        //    flag = 1;
                        //}
                        //else if (cbbDevice.SelectedIndex == 2 && flag2 == 0)
                        //{
                        //    intType = 152;
                        //    flag1 = 1;
                        //} else {
                        //    if (flag ==1)
                        //    {
                        //        intType = 151;
                        //    }
                        //    if (flag1 == 1)
                        //    {
                        //        intType = 152;
                        //    }
                        //    flag2 = 1;
                        //} 
                        if (cbbDevice.SelectedIndex == 1)
                        {
                            intType = 151;
                        }
                        if (cbbDevice.SelectedIndex == 2)
                        {
                            intType = 152;
                        }
                    }

                    int count = 0;
                    int index = 0;
                    if (IsAdd(intType, ref count, ref index))
                    {
                        //count += 1;
                        if (intType == 9)//多流速
                        {
                            for (int i = 0; i < sp1.Controls.Count; i++)
                            {
                                //if (sp1.Controls[i].Tag.ToString() != intType.ToString())
                                //{
                                //    Common.ShowMessage("多流速不允许添加其他设备类型，请删除添加的设备类型！");
                                //    return;
                                //}

                                if (sp1.Controls[i].Tag.ToString() == "0" || sp1.Controls[i].Tag.ToString() == "1" || sp1.Controls[i].Tag.ToString() == "2" || sp1.Controls[i].Tag.ToString() == "8" || sp1.Controls[i].Tag.ToString() == "9")
                                {
                                    Common.ShowMessage("多流速不允许添加水位、流速、流量、水温、多流速，请删除添加的设备类型！");
                                    return;
                                }
                            }

                            WaterLevelAndCurrentSpeeds wc = new WaterLevelAndCurrentSpeeds(this);
                            wc.InitValue(intType, 0, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(wc);
                            wc.Add();
                        }
                        else
                        {
                            if (intType == 0 || intType == 1 || intType == 2 || intType == 8 || intType == 9)
                            {
                                for (int i = 0; i < sp1.Controls.Count; i++)
                                {
                                    if (sp1.Controls[i].Tag.ToString() == "9")
                                    {
                                        Common.ShowMessage("已添加多流速，不允许添加水位、流速、流量、水温、多流速设备类型！");
                                        return;
                                    }
                                }
                            }
                        }

                        if (intType == 0)//水位计
                        {
                            WaterLevel wl = new WaterLevel(this);
                            wl.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(wl);
                        }

                        if (intType == 1)//流速
                        {
                            CurrentSpeed cs = new CurrentSpeed(this);
                            cs.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(cs);
                        }

                        if (intType == 2)//流量计
                        {
                            if (cbbDevice.SelectedIndex == 2 || cbbDevice.SelectedIndex == 3)
                            {
                                WaterLevelAndCurrentSpeed wc = new WaterLevelAndCurrentSpeed(this);
                                wc.InitValue(intType, index, cbbDevice.SelectedIndex);
                                sp1.Controls.Add(wc);
                            }
                            else if (cbbDevice.SelectedIndex == 1)
                            {
                                Flowmeters1 fl1 = new Flowmeters1(this);
                                fl1.InitValue(intType, index, cbbDevice.SelectedIndex);
                                sp1.Controls.Add(fl1);
                            }
                            else
                            {
                                Flowmeters fl = new Flowmeters(this);
                                fl.InitValue(intType, index, cbbDevice.SelectedIndex);
                                sp1.Controls.Add(fl);
                            }
                        }

                        if (intType == 3)//闸位计
                        {
                            GatePosition gp = new GatePosition(this);
                            gp.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(gp);
                        }

                        if (intType == 4)//雨量计
                        {
                            RainFall rf = new RainFall();
                            rf.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(rf);
                        }

                        if (cbbType.SelectedIndex == 5)//水质
                        {
                            WaterQuality wq = new WaterQuality(this);
                            wq.InitValue(cbbType.SelectedIndex, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(wq);
                            listWaterTemperature.Add((cbbDevice.SelectedIndex + 5).ToString());
                        }

                        if (intType == 6)//相机
                        {
                            Camera c = new Camera();
                            c.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(c);
                        }

                        if (intType == 7)//摄像头
                        {
                            Video v = new Video();
                            v.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(v);
                        }

                        if (intType == 8)//水温
                        {
                            WaterTemperature w = new WaterTemperature();
                            w.InitValue(intType, index, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(w);
                        }

                        if (intType == 10)//土壤温湿度
                        {
                            Soil s = new Soil(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }

                        if (intType == 11)//渗压力
                        {
                            OsmoticPressure s = new OsmoticPressure(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }

                        if (intType == 12)//风速
                        {
                            WindSpeed s = new WindSpeed(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }

                        if (intType == 13)//风向
                        {
                            WindDir s = new WindDir(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }

                        if (intType == 14)//大气温湿压
                        {
                            Atmosphere s = new Atmosphere(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }
                        //if (intType == 15)
                        //{
                        //    if (cbbDevice.SelectedIndex == 2)
                        //    {
                        //        Pm10 wc = new Pm10(this);
                        //        wc.InitValue(intType, index, cbbDevice.SelectedIndex);
                        //        sp1.Controls.Add(wc);
                        //    }
                        //    else if (cbbDevice.SelectedIndex == 1)
                        //    {
                        //        Pm25 fl1 = new Pm25(this);
                        //        fl1.InitValue(intType, index, cbbDevice.SelectedIndex);
                        //        sp1.Controls.Add(fl1);
                        //    }
                        //    else
                        //    {
                        //        PmGas fl = new PmGas(this);
                        //        fl.InitValue(intType, index, cbbDevice.SelectedIndex);
                        //        sp1.Controls.Add(fl);
                        //    }
                        //}
                        if (intType == 15)//PM传感器
                        {
                            PmGas fl = new PmGas(this);
                            fl.InitValue(intType, index, 0);
                            sp1.Controls.Add(fl);
                        }
                        if (intType == 151)//PM传感器
                        {
                            //if (cbbDevice.SelectedIndex == 0)
                            //{
                            //    PmGas fl = new PmGas(this);
                            //    fl.InitValue(intType, index, cbbDevice.SelectedIndex);
                            //    sp1.Controls.Add(fl);
                            //}
                            //else
                            //{
                                Pm25 fl1 = new Pm25(this);
                                fl1.InitValue(intType, index, 0);
                                sp1.Controls.Add(fl1);
                            //}
                            
                        }
                        if (intType == 152)//PM传感器
                        {
                            //if (cbbDevice.SelectedIndex == 0)
                            //{
                            //    PmGas fl = new PmGas(this);
                            //    fl.InitValue(intType, index, cbbDevice.SelectedIndex);
                            //    sp1.Controls.Add(fl);
                            //}
                            //else
                            //{
                                Pm10 wc = new Pm10(this);
                                wc.InitValue(intType, index, 0);
                                sp1.Controls.Add(wc);
                            //}
                               
                        }
                        if (intType == 16)//气象站(七要素)
                        {
                            MeteorologicalStationSeven s = new MeteorologicalStationSeven(this);
                            s.InitValue(cbbType.SelectedIndex, count, cbbDevice.SelectedIndex);
                            sp1.Controls.Add(s);
                        }

                        ControlsSort();
                        InitFlowFs();
                    }
                    else
                    {
                        Common.ShowMessage("已超过添加设备的最大数量");
                    }
                }
            }
            catch
            {
                Common.ShowErrorMessage("添加设备失败！");
            }
        }

        /// <summary>
        /// 设备类型选择
        /// </summary>
        private void cbbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbbDevice.Properties.Items.Clear();
            if (cbbType.SelectedIndex == 0)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.WaterLevelList);
            }

            if (cbbType.SelectedIndex == 1)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.CurrentSpeedList);
            }

            if (cbbType.SelectedIndex == 2)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.FlowmeterList);
            }

            if (cbbType.SelectedIndex == 3)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.GatePositionList);
            }

            if (cbbType.SelectedIndex == 4)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.RainFallList);
            }

            if (cbbType.SelectedIndex == 5)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.WaterQualityList);
            }

            if (cbbType.SelectedIndex == 6)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.CameraList);
            }

            if (cbbType.SelectedIndex == 7)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.VideoList);
            }

            if (cbbType.SelectedIndex == 8)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.WaterTemperatureList);
            }

            if (cbbType.SelectedIndex == 9)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.CurrentSpeedList1);
            }

            if (cbbType.SelectedIndex == 10)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.SoilList);
            }

            if (cbbType.SelectedIndex == 11)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.OsmoticPressureList);
            }

            if (cbbType.SelectedIndex == 12)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.WindSpeedList);
            }

            if (cbbType.SelectedIndex == 13)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.WindDirList);
            }
            if (cbbType.SelectedIndex == 14)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.AtmosphereList);
            }
            if (cbbType.SelectedIndex == 15)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.PmList);
            }
            if (cbbType.SelectedIndex == 16)
            {
                this.cbbDevice.Properties.Items.AddRange(Common.MeteorologicalStationSevenList);
            }

            if (cbbDevice.Properties.Items.Count > 0)
            {
                cbbDevice.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 计算方式1选择
        /// </summary>
        private void cbbJs1_SelectedIndexChanged(object sender, EventArgs e)
        {
            InitDm(cbbJs1, cbbDm1);
        }

        /// <summary>
        /// 计算方式2选择
        /// </summary>
        private void cbbJs2_SelectedIndexChanged(object sender, EventArgs e)
        {
            InitDm(cbbJs2, cbbDm2);
        }

        /// <summary>
        /// 断面1选择
        /// </summary>
        private void cbbDm1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbJs1.SelectedItem != null)
            {
                int intFs = (cbbJs1.SelectedItem as ListItem).Value;
                int intDm = cbbDm1.SelectedIndex;
                int intFs1 = cbbJs2.SelectedItem != null ? (cbbJs2.SelectedItem as ListItem).Value : -1;
                int intDm1 = cbbDm2.SelectedIndex;
                btnWaterLevelSetting.Location = new Point(1022, 23);
                btnYc1.Visible = false;

                if ((intFs == 1 && intDm == 5) || (intFs == 4 && intDm == 0))
                {
                    btnYc1.Visible = true;
                    btnWaterLevelSetting.Location = new Point(1022, 23);
                }
                else
                {
                    btnWaterLevelSetting.Location = btnYc1.Location;
                }

                btnWaterLevelSetting.Visible = false;
                if ((intFs == 0 && intDm == 6) || (intFs1 == 0 && intDm1 == 6))
                {
                    btnWaterLevelSetting.Visible = true;
                }
            }
        }

        /// <summary>
        /// 断面2选择
        /// </summary>
        private void cbbDm2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbJs2.SelectedItem != null)
            {
                int intFs = (cbbJs2.SelectedItem as ListItem).Value;
                int intDm = cbbDm2.SelectedIndex;
                int intFs1 = cbbJs1.SelectedItem != null ? (cbbJs1.SelectedItem as ListItem).Value : -1;
                int intDm1 = cbbDm1.SelectedIndex;
                btnYc2.Visible = false;
                btnWaterLevelSetting.Location = new Point(1022, 23);
            
                if (intFs == 1 && intDm == 5)
                {
                    btnYc2.Visible = true;
                    btnWaterLevelSetting.Location = new Point(1022, 23);
                }
                else
                {
                    btnWaterLevelSetting.Location = btnYc1.Location;
                }

                btnWaterLevelSetting.Visible = false;
                if ((intFs == 0 && intDm == 6) || (intFs1 == 0 && intDm1 == 6))
                {
                    btnWaterLevelSetting.Visible = true;
                }
            }
        }

        ///// <summary>
        ///// 选择流量1积算
        ///// </summary>
        //private void chkJs1_CheckedChanged(object sender, EventArgs e)
        //{
        //    if (chkJs1.Checked)
        //    {
        //        if (cbbJs1.Properties.Items.Count == 0)
        //        {
        //            Common.ShowErrorMessage("请选择流量计算来源！");
        //            chkJs1.Checked = false;
        //            return;
        //        }

        //        if (cbbDm1.Properties.Items.Count == 0)
        //        {
        //            Common.ShowErrorMessage("请选择流量槽断面！");
        //            chkJs1.Checked = false;
        //            return;
        //        }

        //        if (f1 == null)
        //        {
        //            f1 = new Flowmeter();
        //            f1.InitValue("流量1设置", 0, (cbbJs1.SelectedItem as ListItem).Value, cbbDm1.SelectedIndex);
        //            //f1.InitShow(cbbJs1.SelectedIndex, cbbDm1.SelectedIndex);
        //            //sp2.Controls.Clear();
        //            //sp2.Controls.Add(f1);
        //            //if (f2 != null)
        //            //{
        //            //    sp2.Controls.Add(f2);
        //            //}
        //        }
        //    }
        //    else
        //    {
        //        //sp2.Controls.Remove(f1);
        //        f1 = null;
        //    }
        //}

        ///// <summary>
        ///// 选择流量2积算
        ///// </summary>
        //private void chkJs2_CheckedChanged(object sender, EventArgs e)
        //{
        //    if (chkJs2.Checked)
        //    {
        //        if (cbbJs2.Properties.Items.Count == 0)
        //        {
        //            Common.ShowErrorMessage("请选择流量计算来源！");
        //            chkJs2.Checked = false;
        //            return;
        //        }

        //        if (cbbDm2.Properties.Items.Count == 0)
        //        {
        //            Common.ShowErrorMessage("请选择流量槽断面！");
        //            chkJs2.Checked = false;
        //            return;
        //        }

        //        if (f2 == null)
        //        {
        //            f2 = new Flowmeter();
        //            f2.InitValue("流量2设置", 1, (cbbJs2.SelectedItem as ListItem).Value, cbbDm2.SelectedIndex);
        //            //f2.InitShow(cbbJs2.SelectedIndex, cbbDm2.SelectedIndex);
        //            //sp2.Controls.Clear();
        //            //if (f1 != null)
        //            //{
        //            //    sp2.Controls.Add(f1);
        //            //}
        //            //sp2.Controls.Add(f2);
        //        }
        //    }
        //    else
        //    {
        //        //sp2.Controls.Remove(f2);
        //        f2 = null;
        //    }
        //}

        private void txtBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //如果输入的不是退格和数字，则屏蔽输入
            if (!(e.KeyChar == '\b' || (e.KeyChar >= '0' && e.KeyChar <= '9')))
            {
                e.Handled = true;
            }
        }

        public class ListItem : Object
        {
            public string Text { get; set; }

            public int Value { get; set; }

            public ListItem(string text, int value)
            {
                this.Text = text;
                this.Value = value;
            }

            public override string ToString()
            {
                return this.Text;
            }
        }

        /// <summary>
        /// 工作模式选择
        /// </summary>
        private void cbb2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbb2.SelectedIndex == 1)
            {
                labelControl31.Visible = true;
                nud3.Visible = true;
                labelControl8.Visible = true;
            }
            else
            {
                labelControl31.Visible = false;
                nud3.Visible = false;
                labelControl8.Visible = false;
            }
        }

        /// <summary>
        /// 基本配置-高级配置
        /// </summary>
        private void btnOther_Click(object sender, EventArgs e)
        {
            groupControl9.Visible = true;
        }

        /// <summary>
        /// 基本配置-高级配置关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            groupControl9.Visible = false;
        }

        private void btnYc1_Click(object sender, EventArgs e)
        {
            MessageInfo.SendMessage(ParameterConfig.mainFormName, ParameterConfig.debugMsg + 2, 13, 1);
        }

        private void btnYc2_Click(object sender, EventArgs e)
        {
            MessageInfo.SendMessage(ParameterConfig.mainFormName, ParameterConfig.debugMsg + 2, 13, 2);
        }

        private void cbb13_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowEthernet();
        }

        private void cbb23_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowEthernet();
        }

        private void cbb33_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowEthernet();
        }

        /// <summary>
        /// 打开流量1参数设置
        private void btnDm1_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbbJs1.Properties.Items.Count == 0)
                {
                    Common.ShowErrorMessage("请选择流量计算来源！");
                    return;
                }

                if (cbbDm1.Properties.Items.Count == 0)
                {
                    Common.ShowErrorMessage("请选择流量槽断面！");
                    return;
                }

                int intValue = cbbJs1.SelectedItem != null ? (cbbJs1.SelectedItem as ListItem).Value : -1;
                if (intValue == 3 && cbbDm1.Properties.Items.Count == 1)
                {
                    return;
                }

                if (intValue == 4 && cbbDm1.Properties.Items.Count == 0)
                {
                    return;
                }

                FlowCalculation fc = new FlowCalculation();
                fc.InitValue("流量1设置", 0, (cbbJs1.SelectedItem as ListItem).Value, cbbDm1.SelectedIndex);
                fc.StartPosition = FormStartPosition.CenterParent;
                fc.ShowDialog();
            }
            catch
            {
                Common.ShowErrorMessage("打开流量1参数设置失败！");
            }
        }

        /// <summary>
        /// 打开流量2参数设置
        /// </summary>
        private void btnDm2_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbbJs2.Properties.Items.Count == 0)
                {
                    Common.ShowErrorMessage("请选择流量计算来源！");
                    return;
                }

                if (cbbDm2.Properties.Items.Count == 0)
                {
                    Common.ShowErrorMessage("请选择流量槽断面！");
                    return;
                }

                int intValue = cbbJs2.SelectedItem != null ? (cbbJs2.SelectedItem as ListItem).Value : -1;
                if (intValue == 3 && cbbDm2.Properties.Items.Count == 1)
                {
                    return;
                }

                FlowCalculation fc = new FlowCalculation();
                fc.InitValue("流量2设置", 1, (cbbJs2.SelectedItem as ListItem).Value, cbbDm2.SelectedIndex);
                fc.StartPosition = FormStartPosition.CenterParent;
                fc.ShowDialog();
            }
            catch
            {
                Common.ShowErrorMessage("打开流量2参数设置失败！");
            }
        }

        /// <summary>
        /// 流量1积算调试
        /// </summary>
        private void btnDebug1_Click(object sender, EventArgs e)
        {
            MessageInfo.SendMessage(ParameterConfig.mainFormName, ParameterConfig.debugMsg, 0x0A, 1);
        }

        /// <summary>
        /// 流量2积算调试
        /// </summary>
        private void btnDebug2_Click(object sender, EventArgs e)
        {
            MessageInfo.SendMessage(ParameterConfig.mainFormName, ParameterConfig.debugMsg, 0x0A, 2);
        }

        /// <summary>
        /// 水位流量标定
        /// </summary>
        private void btnWaterLevelSetting_Click(object sender, EventArgs e)
        {
            MessageInfo.SendMessage(ParameterConfig.mainFormName, ParameterConfig.debugMsg + 3, 13, 1);
        }

        private void cbbYt2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbYt2.SelectedIndex == 1)
            {
                ipAddressInput1.Enabled = false;
                ipAddressInput2.Enabled = false;
                ipAddressInput3.Enabled = false;
                ipAddressInput4.Enabled = false;
                ipAddressInput5.Enabled = false;
            }
            else
            {
                ipAddressInput1.Enabled = true;
                ipAddressInput2.Enabled = true;
                ipAddressInput3.Enabled = true;
                ipAddressInput4.Enabled = true;
                ipAddressInput5.Enabled = true;
            }
        }
   
    }
}
